Spring configuration problem?

Posted on 02/06/2009 by Charalampos Chrysikopoulos

I think, I have a spring configuration problem. I use eclipse with the spring tool plug-in enabled for my project. I used to have one configuration file for my business logic beans and for the test environment. Then, I decided to split the configuration file in two files, one for the test environment and one for the business logic beans, do that the second one would be the base for the actuall application.

The configuration file is system-test-config.xml

<br /><br /><beans xmlns="http://www.springframework.org/schema/beans" xsi="http://www.w3.org/2001/XMLSchema-instance" context="http://www.springframework.org/schema/context" aop="http://www.springframework.org/schema/aop" schemalocation="http://www.springframework.org/schema/beans             http://www.springframework.org/schema/beans/spring-beans-2.5.xsd            http://www.springframework.org/schema/context            http://www.springframework.org/schema/context/spring-context-2.5.xsd            http://www.springframework.org/schema/aop             http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"><br /><br /><import resource="classpath:application-config.xml"><br /><br /><aop:aspectj-autoproxy class="true"><br /><context:annotation-config><br /><br /><bean id="pmf" class="org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean"><br />    <property name="jdoProperties"><br />        <props><br />            <prop key="javax.jdo.PersistenceManagerFactoryClass">org.datanucleus.jdo.JDOPersistenceManagerFactory</prop><br />            <prop key="javax.jdo.option.ConnectionURL">jdbc:hsqldb:mem:dbname</prop><br />            <prop key="javax.jdo.option.ConnectionUserName">sa</prop><br />            <prop key="javax.jdo.option.ConnectionPassword"></prop><br />            <prop key="javax.jdo.option.ConnectionDriverName">org.hsqldb.jdbcDriver</prop><br />        <br />            <prop key="datanucleus.autoCreateTables">true</prop><br />        </props><br />    </property><br /></bean><br /><br /><bean id="jdoTransactionManager" class="org.springframework.orm.jdo.JdoTransactionManager"><br />    <property name="persistenceManagerFactory"><ref local="pmf"></ref><br /></property><br /><br /><bean id="sampleServiceImpl" class="gr.open.thohapi.services.SampleServiceImpl"><br /><property name="sampleDAO"><br /><ref local="sampleDAOImpl"><br /></ref><br /></property><br /><br /><bean id="sampleService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"><br /> <qualifier value="sampleServie"><br />    <property name="transactionManager"><ref local="jdoTransactionManager"></ref><br />    <property name="target"><br /><ref local="sampleServiceImpl"><br />    </ref><br />    <property name="transactionAttributes"><br />        <props><br />            <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop><br />            <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop><br />            <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop><br />            <prop key="store*">PROPAGATION_REQUIRED</prop><br />            <prop key="delete*">PROPAGATION_REQUIRED</prop><br />        </props><br />    </property><br /></property><br /></property><br /></qualifier></bean></bean></bean></context:annotation-config></aop:aspectj-autoproxy></import></beans>

and the application file is application-config.xml

<br /><br /><beans xmlns="http://www.springframework.org/schema/beans" xsi="http://www.w3.org/2001/XMLSchema-instance" context="http://www.springframework.org/schema/context" schemalocation="http://www.springframework.org/schema/beans             http://www.springframework.org/schema/beans/spring-beans-2.5.xsd            http://www.springframework.org/schema/context            http://www.springframework.org/schema/context/spring-context-2.5.xsd"><br /><br /><bean id="sampleDAOImpl" class="gr.open.thohapi.daos.SampleDAOImpl"><br /><property name="persistenceManagerFactory"><br /><ref local="pmf"><br /></ref><br /></property><br /><br /></bean><br /></beans>

With this configurations files it should be working, shouldn't it? The test config xml imports the application configuration, so it should recognize the sampleDAOImpl bean defined in it. But it doesn't.

Eclipse (through the sprint tool) shows me an error:
cvc-id.1: There is no ID/IDREF binding for IDREF 'sampleDAOImpl'.

and the execution of the test has as result the following exception:
Caused by: org.xml.sax.SAXParseException: cvc-id.1: There is no ID/IDREF binding for IDREF 'sampleDAOImpl'.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleEndElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
... 26 more

Solution:
After searching a little bit in google, I found this. It seams that there is a difference between local declared beans and not local beans. The bean sampleDAOImpl is defined in a separate xml file, so I should reference to it not as a local bean, using the ref attribute of the property tag. That's all!

This entry was posted in configuration, spring and tagged by Charalampos Chrysikopoulos

Add new comment