Announcement Announcement Module
Collapse
No announcement yet.
help!can't register my own beans Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • help!can't register my own beans

    ERROR [org.springframework.web.context.ContextLoader] - <Context initialization failed>
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'appManager' defined in ServletContext resource [/WEB-INF/config/applicationContext.xml]: Cannot resolve reference to bean 'userManager' while setting bean property 'userManager'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userManager' defined in ServletContext resource [/WEB-INF/config/applicationContext.xml]: Cannot resolve reference to bean 'userManagerTarget' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userManagerTarget' defined in ServletContext resource [/WEB-INF/config/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: sessionFactory or hibernateTemplate is required
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userManager' defined in ServletContext resource [/WEB-INF/config/applicationContext.xml]: Cannot resolve reference to bean 'userManagerTarget' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userManagerTarget' defined in ServletContext resource [/WEB-INF/config/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: sessionFactory or hibernateTemplate is required
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userManagerTarget' defined in ServletContext resource [/WEB-INF/config/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: sessionFactory or hibernateTemplate is required
    java.lang.IllegalArgumentException: sessionFactory or hibernateTemplate is required
    at org.springframework.orm.hibernate3.support.Hiberna teDaoSupport.checkDaoConfig(HibernateDaoSupport.ja va:112)
    at org.springframework.dao.support.DaoSupport.afterPr opertiesSet(DaoSupport.java:43)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1091)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:396)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:233)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:186)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:106)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1046)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:857)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:378)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:233)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:186)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:106)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1046)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:857)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:378)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:233)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:283)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:313)
    at org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:139)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:246)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:184)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 49)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3692)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4127)
    at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:759)
    at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:739)
    at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:524)
    at org.apache.catalina.startup.HostConfig.deployDescr iptor(HostConfig.java:603)
    at org.apache.catalina.startup.HostConfig.deployDescr iptors(HostConfig.java:535)
    at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:470)
    at org.apache.catalina.startup.HostConfig.start(HostC onfig.java:1118)
    at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:310)
    at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1020)
    at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:718)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1012)
    at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:442)
    at org.apache.catalina.core.StandardService.start(Sta ndardService.java:450)
    at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:680)
    at org.apache.catalina.startup.Catalina.start(Catalin a.java:536)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:275)
    at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:413)

  • #2
    my applicationContext.xml is like this:

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="mappingResources">
    <!--value>org/hxmt/hcmp/db/hibernate/hbm/HxmtUser.hbm.xml</value-->
    <value>db/hibernate/hbm/HxmtUser.hbm.xml</value>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.generate_statistics">true</prop>
    </props>
    </property>
    <property name="eventListeners">
    <map>
    <entry key="merge">
    <bean class="org.springframework.orm.hibernate3.support. IdTransferringMergeEventListener" />
    </entry>
    </map>
    </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <!-- Generic manager facade that can be used to do basic CRUD operations on any objects -->
    <bean id="appManager" class="org.hxmt.hcmp.core.AppManagerImpl">
    <property name="userManager" ref="userManager" />
    <!--property name="groupManager" ref="groupManager"/-->
    <!--property name="roleManager" ref="roleManager" /-->
    </bean>
    <!-- the business facade use below-->
    <bean id="userManagerTarget" class="org.hxmt.hcmp.bos.impl.UserManagerImpl">
    <property name="userDao" ref="userDao"/>
    </bean>

    <bean id="userManager" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager" ref="transactionManager"/>
    <property name="target" ref="userManagerTarget"/>
    <property name="transactionAttributes">
    <props>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="store*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    Comment


    • #3
      Hi

      Please post your XML configuration (or at least the relevant section).

      I would hazard a guess that your 'userManagerTarget' bean needs to be injected with a 'SessionFactory' or a 'HibernateTemplate' reference (as per your stack trace).

      Error creating bean with name 'userManagerTarget' defined in ServletContext resource [/WEB-INF/config/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: sessionFactory or hibernateTemplate is required
      Cheers
      Rick

      Comment


      • #4
        i've also added relative .jar

        thanks rick, the whole xml is attached here.

        <?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="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
        <property name="locations">
        <list>
        <value>/WEB-INF/config/jdbc.properties</value>
        </list>
        </property>
        </bean>

        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        </bean>

        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="mappingResources">
        <!--value>org/hxmt/hcmp/db/hibernate/hbm/HxmtUser.hbm.xml</value-->
        <value>db/hibernate/hbm/HxmtUser.hbm.xml</value>
        </property>
        <property name="hibernateProperties">
        <props>
        <prop key="hibernate.dialect">${hibernate.dialect}</prop>
        <prop key="hibernate.show_sql">true</prop>
        <prop key="hibernate.generate_statistics">true</prop>
        </props>
        </property>
        <property name="eventListeners">
        <map>
        <entry key="merge">
        <bean class="org.springframework.orm.hibernate3.support. IdTransferringMergeEventListener" />
        </entry>
        </map>
        </property>
        </bean>

        <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
        </bean>

        <!-- Generic manager facade that can be used to do basic CRUD operations on any objects -->
        <bean id="appManager" class="org.hxmt.hcmp.core.AppManagerImpl">
        <property name="userManager" ref="userManager" />
        <!--property name="groupManager" ref="groupManager"/-->
        <!--property name="roleManager" ref="roleManager" /-->
        </bean>
        <!-- the business facade use below-->
        <bean id="userManagerTarget" class="org.hxmt.hcmp.bos.impl.UserManagerImpl">
        <property name="userDao" ref="userDao"/>
        </bean>

        <bean id="userManager" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
        <property name="transactionManager" ref="transactionManager"/>
        <property name="target" ref="userManagerTarget"/>
        <property name="transactionAttributes">
        <props>
        <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
        <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
        <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
        <prop key="insert*">PROPAGATION_REQUIRED</prop>
        <prop key="store*">PROPAGATION_REQUIRED</prop>
        </props>
        </property>
        </bean>


        </beans>

        applilcationContext-dao.xml is :
        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" >
        <beans>
        <!-- UserDao: Hibernate implementation -->
        <bean id="userDao" class="org.hxmt.hcmp.dao.impl.UserDaoImpl">
        <property name="sessionFactory" ref="sessionFactory" />
        </bean>

        <!-- Add new Daos here -->

        </beans>

        Comment


        • #5
          you have to inject the hibernateTemplate or SessionFactory on userManagerTarget:

          <bean id="userManagerTarget" class="org.hxmt.hcmp.bos.impl.UserManagerImpl">
          <property name="userDao" ref="userDao"/>
          <property name="sessionFactory" ref="sessionFactory"/>
          </bean>
          The error message is pretty clear - or am I missing something here?

          Comment


          • #6
            public class UserManagerImpl extends HibernateDaoSupport implements UserManager{
            UserDao userDao;
            .....
            }
            it extends org.springframework.orm.hibernate3.support.Hiberna teDaoSupport,
            and has had hibernateTemplate or SessionFactory already.

            Comment


            • #7
              thank u so much ,costin
              i found this error

              Comment

              Working...
              X