环境是: Struts 2.1.8.1 + Spring 3.0 + Hibernate 3.3.2GA
在配置spring 时如果是一个dao的话,就不报错,但是如果有两个dao的话就报:
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
[code="xml"]
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="employeeDao" class="com.liutan.dao.impl.EmployeeDaoImpl" scope="singleton">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="employeeService" class="com.liutan.service.impl.EmployeeServiceImpl">
<property name="employeeDao" ref="employeeDao"/>
</bean>
<!-- 注释掉下面两个bean就不报错!-->
<bean id="departmentDao" class="com.liutan.dao.impl.DepartmentDaoImpl" scope="singleton">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="departmentService" class="com.liutan.service.impl.DepartmentServiceImpl">
<property name="departmentDao" ref="departmentDao"/>
</bean>
[/code]
以下是dataSource和sessionFactory的代码
[code="xml"]
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/winmrp"/>
<property name="user" value="root"/>
<property name="password" value="root"/>
<property name="minPoolSize" value="1"/>
<property name="maxPoolSize" value="20"/>
<property name="maxIdleTime" value="1800"/>
<property name="acquireIncrement" value="2"/>
<property name="maxStatements" value="0"/>
<property name="initialPoolSize" value="2"/>
<property name="idleConnectionTestPeriod" value="1800"/>
<property name="acquireRetryAttempts" value="30"/>
<property name="breakAfterAcquireFailure" value="true"/>
<property name="testConnectionOnCheckout" value="false"/>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/liutan/bean</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.autoReconnect">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
<prop key="hibernate.connection.url">jdbc:mysql://localhost:3306/winmrp</prop>
<prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
<prop key="hibernate.connection.username">root</prop>
<prop key="hibernate.connection.password">root</prop>
</props>
</property>
</bean>
[/code]