iteye_10548 2010-02-02 16:26
浏览 208
已采纳

S2SH 中的Spring sessionFactory注入配置问题

环境是: 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]

  • 写回答

6条回答 默认 最新

  • unika_ly12 2010-02-03 17:37
    关注

    [quote]
    Error creating bean with name 'departmentService' defined
    [/quote]
    一直以为错误在dao,原来是service有问题,检查下departmentService吧,别告诉我说departmentService你也继承了HibernateDaoSupport :evil:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA