有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

更改bean id时,java“sessionFactory”或“hibernateTemplate”不起作用

在我的应用程序中,我得到以下异常。我使用Spring和Hibernate,dao层主要由myeclipse自动生成

nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
            at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:616)

配置如下所示。自动生成的代码使用bean id作为数据源、sessionFactory和hibernateTemplate,并且运行良好。然后我将bean ID更改为tseDataSource、tseSessionFactory和tsehbernatetemplate。我相应地更新了传递给DAO的hibernateTemplate参数。然后我开始得到上面的错误。当我将这些更改回dataSource、sessionFactory和hibernateTemplate时,应用程序运行良好。但是我必须添加另一个数据源,所以我必须更改这些数据源。是否有任何原因导致在更改这些bean ID时发生此错误

 <bean id="tseDataSource" autowire="byName"
      class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName"
              value="com.mysql.jdbc.Driver">
    </property>
    <property name="url"
              value="jdbc:mysql://10.4.4.4:3306/tse">
    </property>
    <property name="username" value="tse"></property>
    <property name="password" value="tse"></property>
</bean>

<bean id="tseSessionFactory" autowire="byName"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
    <ref bean="tseDataSource" />
</property>
<property name="hibernateProperties">
    <props>
        <prop key="hibernate.dialect">
            org.hibernate.dialect.MySQLDialect
        </prop>
        <prop key="hibernate.show_sql">true</prop>
        <prop key="hibernate.format_sql">true</prop>

    </props>

</property>
<property name="mappingDirectoryLocations">
    <list>
        <value>Conf/hibernate/tse</value>
    </list>
</property>
</bean>
<bean id="tseHibernateTemplate"
      class="org.springframework.orm.hibernate3.HibernateTemplate" autowire="byName" >
<property name="sessionFactory">
    <ref local="tseSessionFactory" />
</property>
</bean>


<bean id="tfDataSource" autowire="byName"
      class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
          value="com.mysql.jdbc.Driver">
</property>
<property name="url"
          value="jdbc:mysql://10.4.4.4:3306/tf">
</property>
<property name="username" value="tf"></property>
<property name="password" value="tf"></property>
</bean>

<bean id="tfSessionFactory" autowire="byName"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
    <ref bean="tfDataSource" />
</property>
<property name="hibernateProperties">
    <props>
        <prop key="hibernate.dialect">
            org.hibernate.dialect.MySQLDialect
        </prop>
        <prop key="hibernate.show_sql">true</prop>
        <prop key="hibernate.format_sql">true</prop>

    </props>

</property>
<property name="mappingDirectoryLocations">
    <value>Conf/hibernate/tf</value>
</property>
</bean>
<bean id="tfHibernateTemplate"
      class="org.springframework.orm.hibernate3.HibernateTemplate" autowire="byName" >
<property name="sessionFactory">
    <ref local="tfSessionFactory" />
</property>
</bean>


<bean id="namesDAO" class="com.NamesDAO"  autowire = "byName" >
<property name="hibernateTemplate" ref="tfHibernateTemplate"/>
</bean>


<bean id="LogDAO"
      class="com.LogDAO"
      autowire="byName">
<property name="hibernateTemplate" ref="tseHibernateTemplate" />

</bean>

共 (0) 个答案