<p>I'd like to create a spring bean that holds the value of a double. Something like:</p>

<pre><code>&lt;bean id="doubleValue" value="3.7"/&gt;
</code></pre>

[{'answer_id': 59852, 'author': 'ScArcher2', 'author_id': 1310, 'author_profile': 'https://Stackoverflow.com/users/1310', 'pm_score': 0, 'selected': False, 'text': "<p>Why don't you just use a <strong>Double</strong>? any reason?</p>\n"}, {'answer_id': 59875, 'author': 'Pavel Feldman', 'author_id': 5507, 'author_profile': 'https://Stackoverflow.com/users/5507', 'pm_score': 5, 'selected': True, 'text': '<p>Declare it like this:</p>\n\n<pre><code>&lt;bean id="doubleValue" class="java.lang.Double"&gt;\n   &lt;constructor-arg index="0" value="3.7"/&gt;\n&lt;/bean&gt;\n</code></pre>\n\n<p>And use like this:</p>\n\n<pre><code>&lt;bean id="someOtherBean" ...&gt;\n   &lt;property name="value" ref="doubleValue"/&gt;\n&lt;/bean&gt;\n</code></pre>\n'}, {'answer_id': 73838, 'author': 'enricopulatzo', 'author_id': 9883, 'author_profile': 'https://Stackoverflow.com/users/9883', 'pm_score': 3, 'selected': False, 'text': '<p>It\'s also worth noting that depending on your need defining your own bean may not be the best bet for you.</p>\n\n<pre><code>&lt;util:constant static-field="org.example.Constants.FOO"/&gt;\n</code></pre>\n\n<p>is a good way to access a constant value stored in a class and default binders also work very well for conversions e.g. </p>\n\n<pre><code>&lt;bean class="Foo" p:doubleValue="123.00"/&gt;\n</code></pre>\n\n<p>I\'ve found myself replacing many of my beans in this manner, coupled with a properties file defining my values (for reuse purposes).  What used to look like this</p>\n\n<pre><code>&lt;bean id="d1" class="java.lang.Double"&gt;\n  &lt;constructor-arg value="3.7"/&gt;\n&lt;/bean&gt;\n&lt;bean id="foo" class="Foo"&gt;\n  &lt;property name="doubleVal" ref="d1"/&gt;\n&lt;/bean&gt;\n</code></pre>\n\n<p>gets refactored into this:</p>\n\n<pre><code>&lt;bean\n  id="propertyFile"\n  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"\n  p:location="classpath:my.properties"\n/&gt;\n&lt;bean id="foo" class="Foo" p:doubleVal="${d1}"/&gt;\n</code></pre>\n'}, {'answer_id': 48786968, 'author': 'Subin Chalil', 'author_id': 2756662, 'author_profile': 'https://Stackoverflow.com/users/2756662', 'pm_score': 0, 'selected': False, 'text': '<p>Spring 2.5+</p>\n\n<p><strong>You can define bean like this in Java config:</strong></p>\n\n<pre><code>@Configuration\npublic class BeanConfig {\n    @Bean\n    public Double doubleBean(){\n        return  new Double(3.7);\n    }\n}\n</code></pre>\n\n<p><strong>You can use this bean like this in your program:</strong></p>\n\n<pre><code>@Autowired\nDouble doubleBean;\n\npublic void printDouble(){\n    System.out.println(doubleBean); //sample usage\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/59850', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6180/']