As stated, most recently used spring boot integrated shiro, in shiroFilter when you want to use a database to dynamically assign permissions to the URL found
@Autowired
Injected bean is null, not injected mapper. Search online for a long time seemed to have no issues, but also strange. Finally found
/** * Shiro生命周期处理器 * * @return */ @Bean(name = "lifecycleBeanPostProcessor") public LifecycleBeanPostProcessor getLifecycleBeanPostProcessor() { return new LifecycleBeanPostProcessor(); }
If this configuration appears in the class, the class of autowired will fail, the solution: separate configuration like this
@Configuration public class ShiroLifecycleBeanPostProcessorConfig { /** * Shiro生命周期处理器 * * @return */ @Bean(name = "lifecycleBeanPostProcessor") public LifecycleBeanPostProcessor getLifecycleBeanPostProcessor() { return new LifecycleBeanPostProcessor(); } }
shiro main arrangement
@Configuration @AutoConfigureAfter(ShiroLifecycleBeanPostProcessorConfig.class) public class ShiroConfig { ... }
Description of the class
1.LifecycleBeanPostProcessor used to call Initializable callback interfaces in the realization of the Shiro bean initialization Initializable interface, the interface in the realization of the call Destroyable callback interface when Shiro bean Destroyable destroyed. As UserRealm on the realization of Initializable, and DefaultSecurityManager achieved Destroyable. For details, refer to their inheritance.
2. Shiro ensure the realization of the internal functions of the bean lifecycle execution
See not really understand, and should be shiro internal bean injection and AOP related.