在啟動Springboot項目時,報錯:org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'shiroFilter' available
第一反應是shiroFilter拼寫錯了。於是檢查相關代碼:
1、注入過濾器的代碼
registration.setFilter(new DelegatingFilterProxy("shiroFilter"));
2、自動注冊Bean的代碼
@Bean("shiroFilter") public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) { ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
發現兩個類中shiroFilter的拼寫都沒有問題。
然后開始debug斷點調試。發現代碼根本就沒有進入自動注冊的Bean的代碼中。與是檢查ShiroConfig的代碼,發現類上邊少寫了@Configuration,好尷尬啊!~