我在申请时遇到以下异常。我使用的是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作为dataSource,sessionFactory和hibernateTemplate,它工作正常。然后我将bean id更改为tseDataSource,tseSessionFactory和tseHibernateTemplate。我相应地更新了传递给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>