Consider defining a bean named 'authenticator' in your configuration.
错误信息:
这是由于我使用的pom的依赖是
<!-- 集成shiro依赖 -->
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-spring-boot-web-starter -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring-boot-web-starter</artifactId>
<version>1.4.0</version>
</dependency>
而在starter的org.apache.shiro.spring.config.web.autoconfigure类已经定义了securityManager,代码如下:
@Bean
@ConditionalOnMissingBean
protected SessionsSecurityManager securityManager(List<Realm> realms) {
return super.securityManager(realms);
}
所以把注入的securityManager
类型换成SessionSecurityManager就可以了
@Bean("securityManager")//定义安全管理器securityManager,注入自定义的realm
public SessionsSecurityManager securityManager(@Qualifier("myRealm") MyRealm myRealm) {
DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
manager.setRealm(myRealm);
return manager;
}