spring boot 中自定义shiro过滤器的拦截顺序

2024-07-29 18:31:29 浏览数 (1)

@boot 中filter SecurityUtils.getSubject()No SecurityManager accessible

场景:

代码语言:javascript复制
     *  在spring boot  spring shiro 
	 *   自定义filter的拦截器 并从doFilter中调用 SecurityUtils.getSubject().getPrincipal() 
	 *   抛出
	 *   No SecurityManager accessible to the calling code, either bound to the 
	 *       org.apache.shiro.util.ThreadContext or as a vm static singleton. 
	 *       This is an invalid application configuration.

解决方案

@Bean(“shiroFilter”) public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) { … }

  • 注意!上图是关键 (相当于web.xml中定义shiro的执行顺序)

0 人点赞