zoukankan      html  css  js  c++  java
  • shiro自定义Realm授权时hibernate事务报错

    问题:

    将shiro框架与ssh框架整合后,在自定义的Realm中注入Dao层,但进行授权时,hibernate框架抛异常

    Could not obtain transaction-synchronized Session for current thread

    无法为当前线程获取事务同步的会话

    解决方法:

    在web.xml中,将shiro核心过滤器的位置放在hibernate扩大session范围的过滤器后边

     1 <!-- 整合shiro -->
     2 <filter>
     3     <filter-name>shiroFilter</filter-name>
     4     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
     5 </filter>
     6 
     7 
     8 <!-- 扩大session作用范围,解决hibernate延迟加载 注意: 必须在struts的filter之前调用 -->
     9 <filter>
    10     <filter-name>openSessionInView</filter-name>
    11     <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
    12 </filter>
    13 
    14 
    15 <!-- 只需保证filter-mapping的位置即可 -->
    16 <filter-mapping>
    17     <filter-name>openSessionInView</filter-name>
    18     <url-pattern>/*</url-pattern>
    19 </filter-mapping>
    20 <filter-mapping>
    21     <filter-name>shiroFilter</filter-name>
    22     <url-pattern>/*</url-pattern>
    23 </filter-mapping>
  • 相关阅读:
    八、多线程爬虫之糗事百科案例
    七、数据提取之JSON与JsonPATH
    Day_03
    六、CSS 选择器:BeautifulSoup4
    Day_01
    Day_02
    图解递归函数
    第十章 提权
    提权篇
    Webshell篇
  • 原文地址:https://www.cnblogs.com/xiaoyao-lxy/p/7637613.html
Copyright © 2011-2022 走看看