Springboot2整合shiro时,自定义realm无法实现自动注入service

  • Post author:
  • Post category:其他

 

在Springboot2整合shiro时,自定义realm无法实现自动注入service,一直出现空指针。

java.lang.NullPointerException

at com.lu.vote1.config.ShiroRealm.doGetAuthenticationInfo(ShiroRealm.java:67)

org.apache.shiro.authc.UnknownAccountException: Realm [com.lu.vote1.config.ShiroRealm@17ad6988] was unable to find account data for the submitted AuthenticationToken [org.apache.shiro.authc.UsernamePasswordToken - admin, rememberMe=false].

在网上找了很久,很多博客都说解决如下:在ShiroConfig.java里面获取shiroRealm对象方法上漏加@Bean注解,但是加上之后还是不可以,后来通过@Qualifier注解实现,代码如下

/*
    安全管理器配置
    */
    @Bean
    public SecurityManager securityManager(@Qualifier("myShiroRealm") MyShiroRealm myShiroRealm){
        DefaultWebSecurityManager securityManager =  new DefaultWebSecurityManager();
        securityManager.setRealm(myShiroRealm);
        return securityManager;
    }

 


版权声明:本文为qq_39098505原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。