sql - Spring inject xml values to properties-config.xml then to a bean -
i noob @ spring, have not find material based on type of injection.
having queries.xml:
<?xml version="1.0" encoding="utf-8"?> <!doctype properties system "http://java.sun.com/dtd/properties.dtd"> <properties> <entry key="sql.accountdao.select"> </entry> <entry key="sql.accountdao.insert"> </entry> </properties>
also have properties-config.xml, containg queries.xml:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd"> <bean id="propertyconfigurer" class="org.springframework.beans.factory.config.propertyplaceholderconfigurer"> <property name="systempropertiesmodename" value="system_properties_mode_override"/> <property name="locations"> <array> <value>classpath:sql/queries.xml</value> </array> </property> </bean> </beans>
and naturally have dao-config.xml, want reference queries.xml:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="namedparamtemplate" class="org.springframework.jdbc.core.namedparam.namedparameterjdbctemplate"> <constructor-arg ref="datasource"/> </bean> <!-- either annotations or xml correct --> <bean id="accountdao" class="dao.impl.accountdaoimpl"> <property name="namedparameterjdbctemplate" ref="namedparamtemplate" /> <property name="insertsql" ????? /> <property name="selectsql" ???? /> </bean> </beans>
tried way in accountdaoimpl.java:
public class accountdaoimpl implements accountdao { private namedparameterjdbctemplate namedparameterjdbctemplate; @value("${sql.accountdao.select}") private string selectsql; @value("${sql.accountdao.insert}") private string insertsql; @required public void setselectsql(string selectsql) { this.selectsql = selectsql; } @required public void setinsertsql(string insertsql) { this.insertsql = insertsql; }
...
annotation based injection did not work. have idea anybody?
both of them in classpath @ web.xml.
exception:
caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'accountdao' defined in class path resource [meta-inf/spring/root/dao-config.xml]: initialization of bean failed; nested exception org.springframework.beans.factory.beaninitializationexception: properties 'insertsql' , 'selectsql' required bean 'accountdao'
in web.xml must declared xml files:
<context-param> <param-name>contextconfiglocation</param-name> <param-value> /web-inf/[your dir]/[your xmlfiles].xml </param-value> </context-param>
Comments
Post a Comment