Announcement Announcement Module
Collapse
No announcement yet.
Problem with bean not found exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with bean not found exception

    I am new bie to spring hibernate application i am getting error when i run testcase based on spring live demo tutorial i am using tomacat 4.1 .
    Let me if any body has faced any problem .

    The error while running the test case .
    [junit] Testcase: testSaveUser(org.appfuse.dao.UserDAOTest): Caused a
    n ERROR
    [junit] No bean named 'userDAO' is defined: org.springframework.beans.factor
    y.support.DefaultListableBeanFactory defining beans [dataSource,sessionFactory,t
    ransactionManager]; Root of BeanFactory hierarchy
    [junit] org.springframework.beans.factory.NoSuchBeanDefini tionException: No
    bean named 'userDAO' is defined: org.springframework.beans.factory.support.Defau
    ltListableBeanFactory defining beans [dataSource,sessionFactory,transactionManag
    er]; Root of BeanFactory hierarchy
    [junit] at org.springframework.beans.factory.support.DefaultL istableBean
    Factory.getBeanDefinition(DefaultListableBeanFacto ry.java:242)
    [junit] at org.springframework.beans.factory.support.Abstract BeanFactory
    .getMergedBeanDefinition(AbstractBeanFactory.java: 498)
    [junit] at org.springframework.beans.factory.support.Abstract BeanFactory
    .getBean(AbstractBeanFactory.java:143)
    [junit] at org.springframework.context.support.AbstractApplic ationContex
    t.getBean(AbstractApplicationContext.java:399)
    [junit] at org.appfuse.dao.UserDAOTest.setUp(UserDAOTest.java :23)


    [junit] Testcase: testAddAndRemoveUser(org.appfuse.dao.UserDAOTest):
    Caused an ERROR
    [junit] No bean named 'userDAO' is defined: org.springframework.beans.factor
    y.support.DefaultListableBeanFactory defining beans [dataSource,sessionFactory,t
    ransactionManager]; Root of BeanFactory hierarchy
    [junit] org.springframework.beans.factory.NoSuchBeanDefini tionException: No
    bean named 'userDAO' is defined: org.springframework.beans.factory.support.Defau
    ltListableBeanFactory defining beans [dataSource,sessionFactory,transactionManag
    er]; Root of BeanFactory hierarchy
    [junit] at org.springframework.beans.factory.support.DefaultL istableBean
    Factory.getBeanDefinition(DefaultListableBeanFacto ry.java:242)
    [junit] at org.springframework.beans.factory.support.Abstract BeanFactory
    .getMergedBeanDefinition(AbstractBeanFactory.java: 498)
    [junit] at org.springframework.beans.factory.support.Abstract BeanFactory
    .getBean(AbstractBeanFactory.java:143)
    [junit] at org.springframework.context.support.AbstractApplic ationContex
    t.getBean(AbstractApplicationContext.java:399)
    [junit] at org.appfuse.dao.UserDAOTest.setUp(UserDAOTest.java :23)


    [junit] TEST org.appfuse.dao.UserDAOTest FAILED

  • #2
    hi

    No bean named 'userDAO' is defined: org.springframework.beans.factor
    y.support.DefaultListableBeanFactory defining beans [dataSource,sessionFactory,t
    ransactionManager];
    the error is obvious , check in your context if exists the bean named 'userDAO'
    if exists (i dont think so ) copy here their definition


    regards

    Comment


    • #3
      As dr_pompeii said, Spring can't find a required bean called 'userDAO'. If you are still having problems, is it possible to see your applicationContext.xml?

      Comment


      • #4
        The application context is

        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
        "http://www.springframework.org/dtd/spring-beans.dtd">

        <beans>
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
        <property name="driverClassName"><value>org.hsqldb.jdbcDrive r</value></property>
        <property name="url"><value>jdbc:hsqldb:db/appfuse</value></property>
        <property name="username"><value>sa</value></property>
        <property name="password"><value></value></property>
        </bean>

        <!-- Hibernate SessionFactory -->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
        <property name="dataSource"><ref local="dataSource"/></property>
        <property name="mappingResources">
        <list>
        <!-- Add list of .hbm.xml files here -->
        <value>org/appfuse/model/User.hbm.xml</value>
        </list>
        </property>
        <property name="hibernateProperties">
        <props>
        <prop key="hibernate.dialect">net.sf.hibernate.dialect.H SQLDialect</prop>
        <prop key="hibernate.hbm2ddl.auto">create</prop>
        </props>
        </property>
        </bean>

        <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
        <bean id="transactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
        <property name="sessionFactory"><ref local="sessionFactory"/></property>
        </bean>

        <!-- Add DAOs here -->

        <bean id="userDAO"
        class="org.appfuse.dao.hibernate.UserDAOHibernate" >
        <property name="sessionFactory">
        <ref local="sessionFactory"/>
        </property>
        </bean>

        <!-- Add Managers here -->
        </beans>

        Comment


        • #5
          I see one more error while starting the apache tomcat its says the applicationContext.xml is not proper .

          The error is

          ERROR - XMLHelper$ErrorLogger.error(48) | Error parsing XML: XML InputStream(2) XML declaration may only begin entities.
          ERROR - Configuration.addInputStream(292) | Could not configure datastore from input stream
          org.dom4j.DocumentException: Error on line 2 of document : XML declaration may only begin entities. Nested exception: XML declaration may only begin entities.
          at org.dom4j.io.SAXReader.read(SAXReader.java:355)
          at net.sf.hibernate.cfg.Configuration.addInputStream( Configuration.java:283)
          at org.springframework.orm.hibernate.LocalSessionFact oryBean.afterPropertiesSet(LocalSessionFactoryBean .java:322)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:801)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:249)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:177)
          at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:159)
          at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:177)
          at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:268)
          at org.springframework.web.context.support.XmlWebAppl icationContext.refresh(XmlWebApplicationContext.ja va:131)
          at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:156)
          at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:97)
          at org.springframework.web.context.ContextLoaderServl et.init(ContextLoaderServlet.java:80)
          at javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
          at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:879)
          at org.apache.catalina.core.StandardWrapper.load(Stan dardWrapper.java:767)
          at org.apache.catalina.core.StandardContext.loadOnSta rtup(StandardContext.java:3483)
          at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:3709)
          at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1147)
          at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:696)
          at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1147)
          at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:310)
          at org.apache.catalina.core.StandardService.start(Sta ndardService.java:449)
          at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:2212)
          at org.apache.catalina.startup.Catalina.start(Catalin a.java:458)
          at org.apache.catalina.startup.Catalina.execute(Catal ina.java:345)
          at org.apache.catalina.startup.Catalina.process(Catal ina.java:129)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:324)
          at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:150)
          Nested exception:
          org.xml.sax.SAXParseException: XML declaration may only begin entities.
          at org.apache.crimson.parser.Parser2.fatal(Parser2.ja va:3376)
          at org.apache.crimson.parser.Parser2.fatal(Parser2.ja va:3364)
          at org.apache.crimson.parser.Parser2.maybePI(Parser2. java:1140)
          at org.apache.crimson.parser.Parser2.maybeMisc(Parser 2.java:1266)
          at org.apache.crimson.parser.Parser2.parseInternal(Pa rser2.java:654)
          at org.apache.crimson.parser.Parser2.parse(Parser2.ja va:337)
          at org.apache.crimson.parser.XMLReaderImpl.parse(XMLR eaderImpl.java:448)
          at org.dom4j.io.SAXReader.read(SAXReader.java:339)
          at net.sf.hibernate.cfg.Configuration.addInputStream( Configuration.java:283)
          at org.springframework.orm.hibernate.LocalSessionFact oryBean.afterPropertiesSet(LocalSessionFactoryBean .java:322)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:801)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:249)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:177)
          at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:159)
          at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:177)
          at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:268)
          at org.springframework.web.context.support.XmlWebAppl icationContext.refresh(XmlWebApplicationContext.ja va:131)
          at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:156)
          at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:97)
          at org.springframework.web.context.ContextLoaderServl et.init(ContextLoaderServlet.java:80)
          at javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
          at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:879)
          at org.apache.catalina.core.StandardWrapper.load(Stan dardWrapper.java:767)
          at org.apache.catalina.core.StandardContext.loadOnSta rtup(StandardContext.java:3483)
          at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:3709)
          at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1147)
          at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:696)
          at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1147)
          at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:310)
          at org.apache.catalina.core.StandardService.start(Sta ndardService.java:449)
          at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:2212)
          at org.apache.catalina.startup.Catalina.start(Catalin a.java:458)
          at org.apache.catalina.startup.Catalina.execute(Catal ina.java:345)
          at org.apache.catalina.startup.Catalina.process(Catal ina.java:129)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:324)
          at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:150)
          INFO - AbstractBeanFactory.destroySingletons(355) | Destroying singletons in factory {org.springframework.beans.factory.support.Default ListableBeanFactory defining beans [dataSource,sessionFactory,transactionManager,userD AO]; Root of BeanFactory hierarchy}
          ERROR - ContextLoader.initWebApplicationContext(108) | Context initialization failed
          org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in resource [/WEB-INF/applicationContext.xml] of ServletContext: Initialization of bean failed; nested exception is net.sf.hibernate.MappingException: org.dom4j.DocumentException: Error on line 2 of document : XML declaration may only begin entities. Nested exception: XML declaration may only begin entities.
          net.sf.hibernate.MappingException: org.dom4j.DocumentException: Error on line 2 of document : XML declaration may only begin entities. Nested exception: XML declaration may only begin entities.
          at net.sf.hibernate.cfg.Configuration.addInputStream( Configuration.java:293)
          at org.springframework.orm.hibernate.LocalSessionFact oryBean.afterPropertiesSet(LocalSessionFactoryBean .java:322)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:801)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:249)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:177)
          at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:159)
          at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:177)
          at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:268)
          at org.springframework.web.context.support.XmlWebAppl icationContext.refresh(XmlWebApplicationContext.ja va:131)
          at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:156)
          at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:97)
          at org.springframework.web.context.ContextLoaderServl et.init(ContextLoaderServlet.java:80)
          at javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
          at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:879)
          at org.apache.catalina.core.StandardWrapper.load(Stan dardWrapper.java:767)
          at org.apache.catalina.core.StandardContext.loadOnSta rtup(StandardContext.java:3483)
          at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:3709)
          at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1147)
          at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:696)
          at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1147)
          at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:310)

          This error started comming when i added this line in the xml

          <value>org/appfuse/model/User.hbm.xml</value>

          Thanks alot in advance for your info

          Comment


          • #6
            You probably have (also?) an error in your hbm file. And if your sessionFactory cannot be started, neither will your userDAO

            Comment


            • #7
              Hi arapolu

              well we have a party of errors

              first question, what version of spring are you using??? ,
              i am asking this to see fi your dtd definition is the correct, that means

              Code:
              <?xml version="1.0" encoding="UTF-8"?>
              <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
              "http://www.springframework.org/dtd/spring-beans.dtd">
              if i dont bad remember when i had problems of version i recieve errors something like you
              Code:
              org.dom4j.DocumentException: Error on line 2 of document : XML declaration may only begin entities. Nested exception: XML declaration may only begin entities.
              if your spring is version 2, you should use this
              Code:
              <?xml version="1.0" encoding="UTF-8"?>
              <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
              "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
              2: why some parts of your xml definition has spaces???
              how this
              Code:
              ework.jdbc.datasource.DriverM anagerDataSource">
              3: i use
              Code:
              <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
              and you use
              Code:
              <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
              4: what version of hibernate are you using??
              i use for instance the version 3 and i must have these beans
              Code:
              <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
              	<property name="sessionFactory">
              		<ref bean="sessionFactory"/>
              	</property>
              </bean>				
              <bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
                    <property name="sessionFactory">
                     	   <ref bean="sessionFactory"/>
                     	</property>
               </bean>
              5: for this
              This error started comming when i added this line in the xml

              <value>org/appfuse/model/User.hbm.xml</value>
              be very sure that the mentionated file is located in the folder class , you can copy by hand, or using ant

              6: your hibernate properties
              , i have something like this
              Code:
              <property name="hibernateProperties">
               <props>
              	<!-- SQL dialect -->
              	<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
              	 <!-- JDBC connection pool (use the built-in) -->
              	<prop key="hibernate.connection.pool_size" >1</prop>
              	<!-- Enable Hibernate's automatic session context management -->
              	<prop key="hibernate.current_session_context_class" >thread</prop>
              	<!-- Disable the second-level cache  -->
              	<prop key="hibernate.cache.provider_class" >org.hibernate.cache.NoCacheProvider</prop>
              	<!-- Echo all executed SQL to stdout -->
              	<prop key="hibernate.show_sql" >true</prop>

              pls check each point, and let us know your advanced

              best wishes

              Comment


              • #8
                I would agree with Marten, this looks Hibernate hbm related. The stacktrace suggests this, along with the fact if you remove the entry it works. I've seen this before when there are weird characters in there, saw this through a HEX editor. Another side note you seem to be using quite an old version of Hibernate.

                Hibernate
                at net.sf.hibernate.cfg.Configuration.addInputStream( Configuration.java:283)
                Works when you remove
                <value>org/appfuse/model/User.hbm.xml</value>

                Comment


                • #9
                  Thanks alot for your response
                  I was going through spring live sample chapter which gives a sample application using spring ,struts and hibernate . the link is

                  http://www.sourcebeat.com/titles/spr...pleChapter.pdf

                  I was using the below jars

                  Hibernate 2.1.4
                  JARs: c3p0-0.8.4.5.jar
                  cglib-full-2.0.1.jar
                  dom4j-1.4.jar
                  ehcache-0.7.jar
                  hibernate2.jar
                  jta.jar
                  odmg-3.0.jar
                  oscache-2.0.1.jar

                  Spring 1.0.2
                  JARs: aopalliance.jar
                  spring.jar

                  And the space between the class name was copy paste mistake while pasting in the forum ,as there is no space in the applicationContext.xml .

                  Is it better to use hibernate 3.0 and spring 2.0 ?

                  Comment


                  • #10
                    I would have thought it makes sense to go with the most recent version. Hibernate 3.x and Spring 2.x have many improvements over previous versions, I don't see any reason to got with the older ones. As for the article, if you copied the hbm from it check there aren't any weird formatting characters.
                    Last edited by karldmoore; Feb 19th, 2007, 02:34 PM. Reason: typo

                    Comment

                    Working...
                    X