spring框架DAO搭配注解配置时注意事项

来源:互联网 发布:js获取指定父节点 编辑:程序博客网 时间:2024/04/30 01:30


如果报错:

org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread


1、注意先后顺序

context:annotation-config/>
<context:component-scan base-package=""/>
<tx:annotation-driven />

2、注意base-package的扫描要独立分开,不要全路径的扫描。

     service部分

      <context:annotation-config/>
 
        <context:component-scan base-package="com.saper.tutorial.service"/>
 
        <context:component-scan base-package="com.saper.tutorial.dao"/>
 
         <tx:annotation-driven transaction-manager="transactionManager"/>

     controller部分
            <context:component-scan base-package="com.saper.tutorial.controller"/>

       红色部分不能简写成如下:
              <context:component-scan base-package="com.saper.tutorial"/>

0 0
原创粉丝点击