1. 程式人生 > >springmvc + shiro 框架遇到的問題

springmvc + shiro 框架遇到的問題

springmvc + shiro 框架遇到的問題

所有請求都返回404

嘗試解決問題

1、查詢容器日誌及應用日,均無報錯資訊
2、啟動引數增加-verbrose:class 列印啟動類載入,找到如下日誌

Oct 18, 2018 10:25:57 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [AsyncAppender-Worker-Thread-4] but has failed to stop it. This is very likely to create a memory leak.
Oct 18, 2018 10:25:57 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [AsyncAppender-Worker-Thread-5] but has failed to stop it. This is very likely to create a memory leak.
Oct 18, 2018 10:25:57 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [AsyncAppender-Worker-Thread-6] but has failed to stop it. This is very likely to create a memory leak.
Oct 18, 2018 10:25:57 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [AsyncAppender-Worker-Thread-7] but has failed to stop it. This is very likely to create a memory leak.
Oct 18, 2018 10:25:57 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [AsyncAppender-Worker-Thread-8] but has failed to stop it. This is very likely to create a memory leak.
Oct 18, 2018 10:25:57 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [AsyncAppender-Worker-Thread-9] but has failed to stop it. This is very likely to create a memory leak.
[Loaded sun.reflect.UnsafeObjectFieldAccessorImpl from /opt/jdk1.8.0_151/jre/lib/rt.jar]

以上日誌列印了兩遍,發現tomcat也啟動了兩遍,貌似在迴圈啟動。。。

後檢視專案配置檔案得以解決,主要涉及到web.xml,及shiro.xml檔案

web.xml檔案內容

<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:application.xml</param-value>
	</context-param>
<servlet>
		<servlet-name>spring</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring-servlet.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>spring</servlet-name>
		<url-pattern>/*</url-pattern>
	</servlet-mapping>
<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>
	<filter-mapping>
		<filter-name>shiroFilter</filter-name>
		<url-pattern>/roleCheck/*</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
	</filter-mapping>

spring-servlet.xml

spring-servlet.xml 中主要配置有mvn相關配置,及其它spring配置的import

遂懷疑報錯跟匯入的spring檔案先後順序有關,將import相關檔案移到application.xml檔案後能正常啟動應用

心想這回沒問題了,然鵝並不是,除錯發現新加的shiro
filter中的區域性屬性未初始化成功

後翻閱spring與springmvc相關資料,大致瞭解下來應用啟動起來後,會初始化兩個容器,一個是spring主容器,一個是mvc的子容器,它是獨立於spring容器的。