日期:2014-05-18  浏览次数:20678 次

spring3+hibernate4 出现的一个问题
错误是这样的:
当我单独测试dao的时候,会报错:No Session found for current thread
但是把到加入到service时,再测试,就没问题
配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"

       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd
       ">
    <context:annotation-config/>
    <context:component-scan base-package="com.zq"/>
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver"></property>
        <property name="url" value="jdbc:mysql://localhost:3306/test"></property>
        <property name="username" value="root"></property>
        <property name="password" value="123456"></property>
        <property name="initialSize" value="10"></property>
        <property name="maxActive" value="1000"></property>
        <property name="maxIdle" value="300"></property>
        <property name="minIdle" value="10"></property>
        <property name="maxWait" value="10000"></property>
        <!--<property name="removeAbandoned" value="true" />
        <property name="removeAbandonedTimeout" value="60"/>
        <property name="logAbandoned" value="true" />
        <property name="testOnBorrow" value="true"/>
        <property name="testWhileIdle" value="true"/>
        <property name="validationQuery" value="select getdate()"/>-->
    </bean>
    <!--整合hibernate-->
    <bean id="sessionFactory