Shiro integrates Springboot and redis, jwt process error shiroFilterChainDefinition
During the process of integrating Springboot and redis, jwt, after writing ShiroConfig, start the project and report an error
Description:
Field shiroFilterChainDefinition in required a bean of type '' that could not be found.
The injection point has the following annotations:
- @(required=true)Action:
Consider defining a bean of type '' in your configuration.
reason
After using the following dependencies, the customized Realm actually conflicts with the authorizer
<dependency> <groupId></groupId> <artifactId>shiro-spring-boot-web-starter</artifactId> <version>1.4.0-RC2</version> </dependency> or <dependency> <groupId></groupId> <artifactId>shiro-redis-spring-boot-starter</artifactId> <version>3.2.1</version> </dependency>
Solution
Annotate @Bean("shiroFilterFactoryBean") on the getShiroConfig file
@Bean("shiroFilterFactoryBean") public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultWebSecurityManager defaultWebSecurityManager){ ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); (defaultWebSecurityManager); Map<String,String> map = new HashMap<>(); ("/user/login","anon"); ("/**", "authc"); (map); return shiroFilterFactoryBean; }
If it cannot be resolved, write a separate bean of ShiroFilterChainDefinition in ShiroConfig
@Bean("shiroFilterFactoryBean") public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultWebSecurityManager defaultWebSecurityManager,ShiroFilterChainDefinition shiroFilterChainDefinition){ ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); (defaultWebSecurityManager); // Add your own filter and name it jwt Map<String, Filter> filters = new HashMap<>(); //Set our custom JWT filter filters .put("jwt", new JwtFilter()); (filters ); (defaultWebSecurityManager); Map<String, String> filterMap = (); (filterMap); return shiroFilterFactoryBean; } @Bean public ShiroFilterChainDefinition shiroFilterChainDefinition() { DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition(); Map<String, String> filterMap = new LinkedHashMap<>(); ("/**", "jwt"); // Mainly verify permissions through annotation (filterMap); return chainDefinition; }
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.