I want to pass the value in the value tag of the property dynamically from the DB. Is this possible in Spring? And how ?
For example in the configuration below.
You can write a another Java class and make it as a bean in Application context and using Spring Expression Language, you have evaluate and get output of the method call.
XML configuration:
<property name="serviceClass"
value="#{webServiceInfoFromDB.wsdlUrl}" />
<property name="username"
value="#{webServiceInfoFromDB.username}" />
WeServiceInfoFromDB.java class:
class WebServiceInfoFromDB {
public String getWsdlUrl() {
// Get the Wsdl URL from DB.
return wsdlUrl;
}
public String getUsername(){
// get the username from DB
return username;
}
XML configuration in application context:
<bean id="webServiceInfoFromDB" class="WebServiceInfoFromDB">
<property name="dataSource" ref="dataSource"/>
</bean>
You can setup property Place Holder with your properties file name that contains key-value pair.
<context:property-placeholder location="config.properties" />
The config.properties file looks like:
wsdl.url = http://server:8080/ServiceAccessPoint
webservice.username = guest
webservice.passward = guest123
Now you can modify your bean definition with ${key}
<bean id="proxyFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="${wsdl.url}"/>
<property name="address" value="${wsdl.url}"/>
<property name="username" value="${webservice.username}"/>
<property name="password" value="${webservice.password}"/>