springboot+shiro报错:Consider defining a bean named 'authenticator' in your configuration.

源码Bean上没有对Bean附名字

 

解决方案:

pom:


     org.apache.shiro
     shiro-spring
     1.4.0
 
    @Bean(name = "shiroFilter")//附名后正确运行
    public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager){

        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();

        shiroFilterFactoryBean.setSecurityManager(securityManager);

        //设置拦截默认访问,如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面
        shiroFilterFactoryBean.setLoginUrl("/login");
        //设置登录成功后需要跳转的页面
        shiroFilterFactoryBean.setSuccessUrl("/welcome");

        Map filterChainDefinitionMap = new LinkedHashMap();
        //配置匿名可访问页面和静态文件
        filterChainDefinitionMap.put("/css/**","anon");
        filterChainDefinitionMap.put("/js/**","anon");
        filterChainDefinitionMap.put("/img/**","anon");
        filterChainDefinitionMap.put("/images/**","anon");
        filterChainDefinitionMap.put("/pic/**","anon");
        filterChainDefinitionMap.put("/login","anon");
        filterChainDefinitionMap.put("/ajaxLogin","anon");
        filterChainDefinitionMap.put("/logout","logout");
        //过滤器规则,从上而下顺序执行,将/**放在最后
        filterChainDefinitionMap.put("/**","authc");
        //设置规则
        shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);

        return shiroFilterFactoryBean;
    }

 

你可能感兴趣的:(shiro)