I'm migrating my Spring configuration from XML bean definitions to class annotations. It's going well (and I like the result) but there's one issue for which I can't find a satisfying answer which involves bean property values.
Suppose I have the following bean definition:
This is clean and it allows me to change the fromAddress property without rebuilding the entire application. But if MailBuilder is annotated with @Component, how can I inject a simple String property into fromAddress?
<bean id="mailBuilder" class="com.xyz.MailBuilder">
<property name="fromAddress" value="firstname.lastname@example.org" />
The best I could come up with so far is to create the following bean definition:
and use the @Resource annotation on the MailBuilder's setter. It works, but it seems awfully verbose for just a simple String property. Plus, if I have 2 builders (one for user activation, the other for lost passwords), I also have to "namespace" these properties to distinguish between them.
<bean id="fromAddress" class="java.lang.String">
<constructor-arg index="0" value="email@example.com" />
Any ideas on how to improve this?
Thanks a bunch!