Announcement Announcement Module
Collapse
No announcement yet.
Spring application context error ! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring application context error !

    Hi everybody !!

    I have a Hibernete 3.0.5-Spring 1.2.1 simple test case with the following stack trace:

    org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'carDao' is defined: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [beanRefFactory]; root of BeanFactory hierarchy
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeanDefinition(DefaultListab leBeanFactory.java:351)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getMergedBeanDefinition(AbstractBeanFa ctory.java:640)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:151)
    at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:540)
    at CarDaoTest.setUp(CarDaoTest.java:42)
    at junit.framework.TestCase.runBare(TestCase.java:125 )
    at junit.framework.TestResult$1.protect(TestResult.ja va:106)
    at junit.framework.TestResult.runProtected(TestResult .java:124)
    at junit.framework.TestResult.run(TestResult.java:109 )
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:2 08)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:478)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:344)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:196)


    The refered Java code with the error is:
    ....
    Code:
    private ApplicationContext ctx = new ClassPathXmlApplicationContext("beanRefFactory.xml");
    ......
    
    protected void setUp() throws Exception {
    		super.setUp();
    		carDAO = (CarDao)ctx.getBean("carDao");
    	}
    ....
    the content of the applicationContext.xml file

    <beans>

    <!-- ========================= GENERAL DEFINITIONS ========================= -->

    <!-- Message source for this context, loaded from localized "messages_xx" files -->
    <bean id="messageSource" class="org.springframework.context.support.Resourc eBundleMessageSource">
    <property name="basename"><value>messages</value></property>
    </bean>

    <!-- applicationContext merge-point -->

    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource"><ref bean="dataSource"/></property>
    <property name="mappingResources">
    <list>
    <value>/Car.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
    <prop key="hibernate.cache.use_query_cache">false</prop>
    <prop key="hibernate.cache.provider_class">org.hibernate .cache.EhCacheProvider</prop>
    <prop key="hibernate.cache.query_cache_factory">org.hibe rnate.cache.StandardQueryCacheFactory</prop>
    </props>
    </property>
    </bean>

    <!-- The Hibernate interceptor -->
    <bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.Hibernat eInterceptor">
    <property name="sessionFactory"><ref bean="sessionFactory"/></property>
    </bean>

    <!-- Car Entity Implementation -->
    <bean id="carDaoTarget" class="CarDaoImpl">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <!-- Car Entity Proxy -->
    <bean id="carDao" class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="target"><ref bean="carDaoTarget"/></property>
    <property name="proxyInterfaces">
    <value>CarDao</value>
    </property>
    <property name="interceptorNames">
    <list>
    <value>hibernateInterceptor</value>
    </list>
    </property>
    </bean>

    </beans>

    The content of the beanRefFactory.xml file is:

    <beans>

    <bean id="beanRefFactory"
    class="org.springframework.context.support.ClassPa thXmlApplicationContext">
    <constructor-arg>
    <list>
    <value>applicationContext.xml</value>
    <value>applicationContext-dataSource.xml</value>
    <!-- beanRefFactory merge-point -->
    </list>
    </constructor-arg>
    </bean>

    </beans>

    Please drop me a few words if anybody has any coments about this error !
    Thanks !!

  • #2
    Work around!

    I have put the datasource bean definition (before into the configurationContext-dataSource.xml file) into the configurationContext.xml file and it works .

    The java code is:

    Code:
    private ApplicationContext ctx = new ClassPathXmlApplicationContext&#40;"configurationContext.xml"&#41;;
    ......
    
    protected void setUp&#40;&#41; throws Exception &#123;
          super.setUp&#40;&#41;;
          carDAO = &#40;CarDao&#41;ctx.getBean&#40;"carDao"&#41;;
       &#125;
    ....
    now, the content of configurationContext.xml is:

    <beans>
    <!-- ========================= DATA SOURCE DEFINITIONS ========================= -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName">
    <value>com.mysql.jdbc.Driver</value>
    </property>
    <property name="url">
    <value>jdbc:mysql://localhost:3306/jbossdb</value>
    </property>
    <property name="username">
    <value>username</value>
    </property>
    <property name="password">
    <value>password</value>
    </property>
    </bean>

    <!-- ========================= GENERAL DEFINITIONS ========================= -->

    <!-- Message source for this context, loaded from localized "messages_xx" files -->
    <bean id="messageSource" class="org.springframework.context.support.Resourc eBundleMessageSource">
    <property name="basename"><value>messages</value></property>
    </bean>

    <!-- applicationContext merge-point -->

    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource"><ref bean="dataSource"/></property>
    <property name="mappingResources">
    <list>
    <value>/Car.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
    <prop key="hibernate.cache.use_query_cache">false</prop>
    <prop key="hibernate.cache.provider_class">org.hibernate .cache.EhCacheProvider</prop>
    <prop key="hibernate.cache.query_cache_factory">org.hibe rnate.cache.StandardQueryCacheFactory</prop>
    </props>
    </property>
    </bean>

    <!-- The Hibernate interceptor -->
    <bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.Hibernat eInterceptor">
    <property name="sessionFactory"><ref bean="sessionFactory"/></property>
    </bean>

    <!-- Car Entity Implementation -->
    <bean id="carDaoTarget" class="CarDaoImpl">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <!-- Car Entity Proxy -->
    <bean id="carDao" class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="target"><ref bean="carDaoTarget"/></property>
    <property name="proxyInterfaces">
    <value>CarDao</value>
    </property>
    <property name="interceptorNames">
    <list>
    <value>hibernateInterceptor</value>
    </list>
    </property>
    </bean>


    So, anybody knows how can I configure different description bean files for using in the same application ?????????. What I did wrong with my first approach??

    Comment

    Working...
    X