java - @Value Annotation and a Database PropertyPlaceHolderConfigurer -
i've got 2 propertyplaceholderconfigurer in spring xml. first 1 obtains application properties file. second 1 obtains user properties database , looks this:
<myconfiguration> <bean id="databaseproperties" class="org.springframework.beans.factory.config.propertyplaceholderconfigurer"> <property name="systempropertiesmodename" value="system_properties_mode_override" /> <property name="properties"> <bean class="org.apache.commons.configuration.configurationconverter" factory-method="getproperties"> <constructor-arg> <ref bean="propertiessource" /> </constructor-arg> </bean> </property> </bean> <bean id="propertiessource" class="org.apache.commons.configuration.databaseconfiguration"> <constructor-arg type="javax.sql.datasource" ref="tomcatdatasource" /> <constructor-arg value="application_properties" /> <constructor-arg value="property_key" /> <constructor-arg value="property_value" /> </bean> <bean id="propertiesservice" class="com.xxx.propertiesserviceimpl"> <property name="propertiessource" ref="propertiessource"></property> </bean> <myconfiguration>
it works , can access these properties injecting 'propertiesservice' like:
@autowired private propertiesservice propertiesservice;
which is:
public class propertiesserviceimpl implements propertiesservice { @autowired private databaseconfiguration propertiessource; private properties properties; @override public string getproperty(string key) { if (properties == null) { properties = configurationconverter.getproperties(propertiessource); } return properties.getproperty(key); } @override public properties getproperties() { if (properties == null) { properties = configurationconverter.getproperties(propertiessource); } return properties; }
the problem use @value annotation not work.
i've tried:
private @value("#{propertiesservice.helloworld}") string helloworld;
and, of course, property exists , reachable through 'propertiesservice' results in next error:
caused by: org.springframework.expression.spel.spelevaluationexception: el1008e:(pos 18): property or field 'helloworld' cannot found on object of type 'com.infraportal.model.properties.propertiesserviceimpl' - maybe not public? @ org.springframework.expression.spel.ast.propertyorfieldreference.readproperty(propertyorfieldreference.java:224) @ org.springframework.expression.spel.ast.propertyorfieldreference.getvalueinternal(propertyorfieldreference.java:94) @ org.springframework.expression.spel.ast.propertyorfieldreference.access$000(propertyorfieldreference.java:46) @ org.springframework.expression.spel.ast.propertyorfieldreference$accessorlvalue.getvalue(propertyorfieldreference.java:374) @ org.springframework.expression.spel.ast.compoundexpression.getvalueinternal(compoundexpression.java:88) @ org.springframework.expression.spel.ast.spelnodeimpl.getvalue(spelnodeimpl.java:120) @ org.springframework.expression.spel.standard.spelexpression.getvalue(spelexpression.java:242) @ org.springframework.context.expression.standardbeanexpressionresolver.evaluate(standardbeanexpressionresolver.java:161)
which makes me think spring looking 'gethelloworld()' method instead using 'getproperty(string key)'
any suggestion?
you need explicitly specify method invoked, on bean referred in el, , supply argument value below
@value("#{propertiesservice.getproperty('helloworld')}") private string helloworld;
Comments
Post a Comment