在这个shirofilter的bean里需要调取服务,但是注入服务不成功,如下调取服务成功解决 /** * ShiroFilterFactoryBean,是个factorybean,为了生成ShiroFilter。 * 它主要保持了三项数据,securityManager,
/** * ShiroFilterFactoryBean,是个factorybean,为了生成ShiroFilter。 * 它主要保持了三项数据,securityManager,filters,filterChainDefinitionManager。 */ @Bean(name = "shiroFilter") public ShiroFilterFactoryBean shiroFilterFactoryBean() { ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); // 必须设置 SecurityManager shiroFilterFactoryBean.setSecurityManager(securityManager()); //如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面 shiroFilterFactoryBean.setLoginUrl("/user/login"); // 未授权界面; shiroFilterFactoryBean.setUnauthorizedUrl("/user/403"); Map在本配置文件里声明一个service的bean,上面代码调取sysUserService()filters = new LinkedHashMap<>(); LogoutFilter logoutFilter = new LogoutFilter(); logoutFilter.setRedirectUrl("/user/login"); //filters.put("perms", urlPermissionsFilter()); shiroFilterFactoryBean.setFilters(filters); Map filterChainDefinitionManager = new LinkedHashMap (); // 配置退出过滤器,其中的具体的退出代码Shiro已经替我们实现了 filterChainDefinitionManager.put("/user/logout", "logout"); filterChainDefinitionManager.put("/user/login", "anon");//anon 可以理解为不拦截 filterChainDefinitionManager.put("/user/toLogin", "anon");//anon 可以理解为不拦截 filterChainDefinitionManager.put("/user/403", "anon");//anon 可以理解为不拦截 List resourcesList=sysUserService().getAuthorities(); for(SysAuthority resources:resourcesList){ if (StringUtils.isNotEmpty(resources.getPath())) { String permission = "perms[" + resources.getPath()+ "]"; filterChainDefinitionManager.put(resources.getPath(),permission); } } filterChainDefinitionManager.put("/**", "authc");//拦截 shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionManager); return shiroFilterFactoryBean; }
@Bean public SysUserService sysUserService() { return new SysUserService(); }