Could not obtain transaction-synchronized Session for current thread

来源:互联网 发布:es6 promise.js 编辑:程序博客网 时间:2024/05/01 01:36

(hibernate4)


已经在web.xml中已经使用

<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

但是任然报错,后来----->

在application.xml

   <!-- 扫描业务逻辑层和模型层 -->
        <context:component-scan base-package="com.dao"/>
        <context:component-scan base-package="com.service"/>
        <context:component-scan base-package="com.action"/>
        <context:component-scan base-package="com.serviceImpl"/>
        <context:component-scan base-package="com.daoImpl"/>
        <!-- 支持注解 -->
        <context:annotation-config/>
        
        <tx:annotation-driven transaction-manager="transactionManager"/>


在serviceImpl中的方法上添加

@Transactional
public void addSubject(Subject subject) {
save(subject);

}

0 0
原创粉丝点击