Could not obtain transaction-synchronized Session for current thread Shiro 引起的事务报错问题

Could not obtain transaction-synchronized Session for current thread  

Shiro 引起的事务报错问题

解决办法:

在MyRealm中做如下修改:(两种方式,任意一种即可 药到病除。)

第一种方法: 在Shiro框架中注入Bean时,不使用@Autowire,使用ApplicationContextRegister.getBean()方法,手动注入bean。保证该方法只有在程序完全启动运行时,才被注入。

第二种方法: 使用 @Autowire  + @Lazy 注解,设置注入到Shiro框架的Bean延时加载(即在第一次使用的时候加载)。

建议使用第二种,直接就好。

参考博客:https://www.cnblogs.com/guoyafenghome/p/9889616.html 

原文地址:https://www.cnblogs.com/Dylan_G/p/11114144.html