關於maven專案tomcat啟動異常org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 解決
錯誤程式碼情況:
嚴重: Exception starting filter shiroFilter
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'shiroFilter' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1060)
at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:326)
at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:235)
at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:199)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4908)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5602)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1260)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:2002)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
No bean named 'shiroFilter' is defined 這句話寫的很清楚,就沒有shiroFilter 就是沒有許可權框架攔截器的定義。
web.xml檔案配置如下:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!-- 修改 Servlet 版本-->
<!-- 配置 DispatcherServlet-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-web.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/spring-web.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>initServlet</servlet-name>
<servlet-class>com.liwei.shiro.web.InitServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/spring-service.xml,
classpath:spring/spring-dao.xml,
</param-value>
</context-param>
<!-- 新增 Shiro 相關配置(應該去官網查詢相應的配置資訊) -->
<!-- The filter-name matches name of a 'shiroFilter' bean inside applicationContext.xml -->
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<!-- Make sure any request you want accessible to Shiro is filtered. /* catches all -->
<!-- requests. Usually this filter mapping is defined first (before all others) to -->
<!-- ensure that Shiro works in subsequent filters in the filter chain: -->
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
可以發現,問題出在shiroFilter沒有被spring容器載入。。。
解決辦法:
只需要在
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/spring-service.xml,
classpath:spring/spring-dao.xml,
classpath:spring/spring-shiro.xml
</param-value>
</context-param>
新增:classpath:spring/spring-shiro.xml
相關文章
- No bean named 'cacheManager' availablej 異常解決BeanAI
- Maven專案報錯:No bean named 'xxxxxx' availableMavenBeanAI
- No Bean named 'Xxx' available 異常報錯BeanAI
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'aaaa' availableSpringFrameworkBeanExceptionAI
- maven外掛 tomcat7啟動報錯,異常如下MavenTomcat
- 報錯:org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xxx'is definedSpringFrameworkBeanException
- Springboot專案啟動異常排查Spring Boot
- 關於SpringMVC的HttpMediaTypeNotSupportedException異常解決SpringMVCHTTPException
- tomcat啟動 ssm專案出現亂碼的解決TomcatSSM
- IDEA專案突然出現異常無法啟動時的有效解決辦法Idea
- Hive多視窗啟動異常(已解決!)Hive
- Maven專案Spring Boot啟動MavenSpring Boot
- Tomcat常見異常及解決方案程式碼例項Tomcat
- idea maven搭建spring報錯:No bean named 'xxx' availableIdeaMavenSpringBeanAI
- 解決一次gitlab因異常關機導致啟動失敗Gitlab
- No bean named 'xxx' is defined錯誤,原因及解決方案Bean
- Spring中出現:No bean named 'XXX' available問題解決SpringBeanAI
- 異常解決——Spring Cloud FeignClient: BeanCreationException: Error creating bean with name XXXServiceSpringCloudclientBeanExceptionError
- spring boot 2.0 專案啟動就關閉問題解決Spring Boot
- spring配置檔案中配置了,但找不到Bean , 啟動不報錯,執行報錯No bean namedSpringBean
- maven專案缺jar問題解決MavenJAR
- tomcat無法啟動的解決方法Tomcat
- 啟動tomcat時 錯誤: 代理丟擲異常 : java.rmi.server.ExportException: Port already in use: 1099的解決辦法TomcatJavaServerExportException
- No bean named BookServiceImpl availableBeanAI
- No bean named ''XXX“ availableBeanAI
- Linux啟動tomcat後執行shutdown.sh關閉時出現異常:Connection refused (Connection refused)LinuxTomcat
- 解決Intellij IDEA2018 的 maven專案每次啟動後都恢復到1.5的JDKIntelliJIdeaMavenJDK
- 啟動Dubbo專案註冊Zookeeper時提示zookeeper not connected異常原理解析
- 解決maven專案控制檯資訊亂碼Maven
- Idea啟動Tomcat無法載入專案,Tomcat沒有對映到IdeaTomcat
- 解決程式中Error creating bean with name 'XXXXX‘ defined in class path resource [application的異常ErrorBeanAPP
- Ionic異常及解決
- Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of typeSpringFrameworkBeanException
- 9. 啟動、關閉tomcatTomcat
- React Native Android 啟動異常React NativeAndroid
- Tomcat啟動報錯:Error starting static Resources解決方法TomcatError
- 程式碼改造引發的NoSuchBeanDefinitionException:no bean named 'XXXX' available問題解決方案BeanExceptionAI
- SpringCloud BeanCurrentlyInCreationException 異常解決方案SpringGCCloudBeanException
- Eclipse中專案Maven相關配置EclipseMaven