Is it possible to add a property from PropertyPlaceholder to a bean via @Autowired? I can't inject it in the xml-context-config because the beans are loaded this way:
<context:component-scan base-package="..."/>
In spring 3.0 (I think from Milestone 3) you can use @Value("${foo.bar}") to access properties from PropertyPlaceholder.
A spring 2.5 approach:
@Component
public class Foo {
@Autowired
@Qualifier("myFlag")
private Boolean flag;
/* ... */
}
and the context
<context:component-scan base-package="..."/>
<context:property-placeholder location="classpath:app.properties"/>
<!-- the flag bean -->
<bean id="myFlag" class="java.lang.Boolean">
<constructor-arg value="${foo.bar}"/>
</bean>
Cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With