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条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧