分类目录归档:开发

[S2SH] Service采用注解形式时getCurrentSession报错“No Hibernate Session bound to thread…”

在采用S2SH框架开发过程中,事务注解写在Service层,可是当Service采用注解形式时,调用到dao层的getCurrentSession时,报错“No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here”

经过多方测试,把<tx:annotation-driven />这句配置写在applicationContext.xml文件中就出上面的错误,当把这句配置移到annomvc-servlet.xml时就可以正常了。

采用配置文件方式定义Service Bean的时候就不会有问题,应该是加载顺序的问题吧,有空的时候研究一下。