现象
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
原文地址:https://www.cnblogs.com/tianzhen45/p/11407248.html
时间: 2024-10-07 21:06:37