I have a bean that has a getter/setter for a String attribute called serverBase.
I have a properties file that is configured in my spring context. I would like to autowire the serverBase on my bean with the value from my properties file called "server_base". how do I do it?
Here are my 3 points of interest:
propreties file (env.properties):
Here is my spring context:Code:server_base=http://192.168.100.52
And here is my class that I need the property injected into:Code:<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:property-placeholder location="classpath*:META-INF/spring/*.properties,classpath:email.properties,classpath:environment.properties"/> <context:spring-configured/> <context:component-scan base-package="net.itxlabs.sanddollar"> <context:exclude-filter expression=".*_Roo_.*" type="regex"/> <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/> </context:component-scan> </beans>
Code:@Configurable public class MyRegistryBean{ @Autowired @Qualifier("properties.server_base") private String serverBase; public String getServerBase() { return this.serverBase; } public void setServerBase(String serverBase) { this.serverBase=serverBase; } }


Reply With Quote
roperty-placeholder/> is for replacing properties in bean definitions using ${placeholders.like.this}.