@Autowired and PropertyPlaceholder

Is it possible to add property from PropertyPlaceholder to bean via @Autowired? I cannot insert it in xml-context-config, since beans loads like this:

<context:component-scan base-package="..."/>
+5
source share
2 answers

In spring 3.0 (I think from Milestone 3) you can use @Value ("$ {foo.bar}") to access properties from PropertyPlaceholder.

+9
source

A spring 2.5 approach:

@Component
public class Foo {
    @Autowired 
    @Qualifier("myFlag")
    private Boolean flag;
    /* ... */
}

and 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>

Greetings

+6
source

All Articles