spring整合shiro配置BUG,Tomcat启动不了:Error during artifact deployment. See server log for details

现象

spring配置shiro权限控制之后,项目无法启动
[2019-08-09 09:00:35,800] Artifact export_web_manager:war exploded: Error during artifact deployment. See server log for details.

Tomcat起不来

原因

将shiro的spring配置放在了springmvc配置中,项目启动报错。
web.xml中的配置

    <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:springmvc.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

<!--4. Shiro权限校验过滤器,这里的filter-name固定,对应spring容器中的过滤器工厂的bean的id-->
	<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>/*</url-pattern>
	</filter-mapping>

web.xml的加载顺序是: <context-param>-> <listener> -> <filter> -> <servlet>。

当shiro的bean配置在springmvc.xml(从dispatcherServlet中加载xml)中,shiro相关的bean在filter加载的后面初始化

shiro配置的filter在容器中找不到相关实例,导致项目无法启动

解决

在web.xml中配置:

    	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath*:applicationContext-*.xml</param-value>
	</context-param>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

	</listener>

单独配置shiro的配置文件applicationContext-shiro.xml

posted @ 2019-08-25 11:06  tianzhen45  阅读(642)  评论(0)    收藏  举报