对不起,如果这是微不足道的,但我对此很陌生。
这是我的pom依赖项:
这一切都是这样的,但如果我取消注释web.xml中的<filter>
部分,我就得到了
一个或多个过滤器无法启动。
错误。我试过谷歌搜索,但没有成功。我正在使用Tomcat 8.我不知道还有什么可以说的问题,因为我试图弄明白自己。我正在关注this链接的教程(使用XML配置)。我尝试了不同的弹簧和弹簧安全版本,但每次战争爆炸时都会爆炸。它给出了上面的错误(当然,应用程序是无法访问的)
我更新了一些我不知道的事情......或者我错过了别的什么?我将在底部发布完整的错误堆栈。
<properties>
<spring.version>4.2.4.RELEASE</spring.version>
<spring.security.version>4.0.3.RELEASE</spring.security.version>
</properties>
<dependencies>
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.security.version}</version>
</dependency>
</dependencies>
的web.xml
<?xml version="1.0" encoding="utf-8" ?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>SpringMVCVezba2</display-name>
<!--filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping-->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
弹簧security.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans = "http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<http auto-config="true">
<intercept-url pattern="/" access="permitAll" />
<intercept-url pattern="/home**" access="permitAll" />
<intercept-url pattern="/store**" access="isAuthenticated" />
<form-login login-page="/home/index" authentication-failure-url="/accessdenied" />
<csrf/>
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="user" password="123" authorities="USER"/>
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
错误堆栈:
16-Feb-2016 21:15:34.292 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
16-Feb-2016 21:15:34.458 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization started
16-Feb-2016 21:15:34.757 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh Refreshing Root WebApplicationContext: startup date [Tue Feb 16 21:15:34 CET 2016]; root of context hierarchy
16-Feb-2016 21:15:34.870 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml]
16-Feb-2016 21:15:35.990 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.register Mapped "{[/home/index || /home/ || /home || /index || /]}" onto public java.lang.String com.nemanjat94.controllers.HomeController.index(org.springframework.ui.Model,com.nemanjat94.models.User)
16-Feb-2016 21:15:36.218 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Tue Feb 16 21:15:34 CET 2016]; root of context hierarchy
16-Feb-2016 21:15:36.327 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Tue Feb 16 21:15:34 CET 2016]; root of context hierarchy
16-Feb-2016 21:15:36.443 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.registerHandler Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
16-Feb-2016 21:15:36.502 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization completed in 2044 ms
16-Feb-2016 21:15:36.518 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more Filters failed to start. Full details will be found in the appropriate container log file
16-Feb-2016 21:15:36.519 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors
16-Feb-2016 21:15:36.531 INFO [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.doClose Closing Root WebApplicationContext: startup date [Tue Feb 16 21:15:34 CET 2016]; root of context hierarchy
[2016-02-16 09:15:36,567] Artifact SpringMVCVezba2:war exploded: Error during artifact deployment. See server log for details.
答案 0 :(得分:3)
所以,显然,问题在于spring-security.xml
无法调用,所以我只是将spring-servlet.xml
的内容移到了spring-security.xml
,这一切现在都按预期工作了。
我希望将contextConfigLocation
放在web.xml
的{{1}}中,但是我无法添加多个(spring-servlet.xml
),但我希望将它们分开。看起来这样做不会很好。
非常感谢@wero的日志提示!
答案 1 :(得分:1)
我的情况下根本没有日志。 发生这种情况是因为我的Filter实现类/方法之一抛出了NullPointerException。
答案 2 :(得分:0)
问题:您的应用程序无法读取“ context-param”中web.xml中提到的“ spring-security.xml”文件。
RCA:按照以下步骤查找为什么/哪个过滤器无法启动。 (通用方法) 步骤1:以“调试模式”启动应用程序,并立即从IDE(Eclipse / Intelija ...)附加远程调试。 第2步:在web.xml文件中提到的Filter类中应用断点。就我而言,它是“ DelegatingFilterProxy”。 步骤3:一旦应用程序达到断点,则启用“ Java Exception BreakPoint-> org.springframework.beans.factory.BeansException”。 步骤4:现在,IDE将向您显示发生异常的确切位置。您可以进一步调试并轻松解决此问题。
解决方案:确保您的应用程序能够读取“ context-param”中提到的spring-security.xml文件,才能解决此问题。
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/appContext.xml /WEB-INF/spring/spring-security.xml
</param-value>
</context-param>
注意:从日志中我没有得到任何信息。
答案 3 :(得分:0)
我有一个类似的问题。我发现我的一个过滤器在init方法中引发了一个异常,它被记录在/usr/local/tomcat/logs/localhost.2019-12-07.log中,而不是'通常'日志(/ usr / local / tomcat / logs / catalina.out或/usr/local/tomcat/logs/catalina.2019-12-07.log)