java - 将过滤器添加到 web.xml 后,一个或多个过滤器无法启动

标签 java xml spring maven spring-mvc

对不起,如果这是微不足道的,但我对此很陌生。

这是我的 pom 依赖项:

这一切都是这样工作的,但是如果我取消注释 <filter>在 web.xml 中我得到了

One or more Filters failed to start.

错误。我尝试用谷歌搜索它,但没有成功。我正在使用 Tomcat 8。对于这个问题,我不知道还能说些什么,因为我正试图自己解决这个问题。我正在按照 this 中的教程进行操作链接(带有 XML 配置)。我尝试了不同的 spring 和 spring security 版本,但每次 war “爆发”时,它都会给出上面的错误(当然,应用程序是无法访问的)

是否更新了我不知道的内容……或者我是否遗漏了其他内容?我将在底部发布完整的错误堆栈。

<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>

网络.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>

spring-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.

最佳答案

所以,显然,问题是无法调用springSecurityFilterChain,所以我只是将spring-security.xml的内容移动到spring- servlet.xml 现在一切正常。

我想通过将 spring-security.xml 放在 web.xmlcontextConfigLocation 中来分离它们,但我做不到添加多个 (spring-servlet.xml),但看起来效果不是很好。

非常感谢@wero 提供的日志记录提示!

关于java - 将过滤器添加到 web.xml 后,一个或多个过滤器无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35442189/

相关文章:

java - Jetty-9.3.12 独立服务器中的 EXIT_ON_INIT_FAILURE

java - 如何将格式如 "java method signature"的字符串分成几部分?

java - 如何在 KeyListener 中检查 Ctrl 已被释放?

javafx 可点击图像 map

javascript - nodejs 使用 cheerio 解析 xml 返回空 CDATA

sql-server - 将先前切碎的 xml 值应用于后续元素

java - 从 Spring boot 加载多个 Angular 项目

java - Android 中的 Jxl.jar

xml - Xquery 处理错误 (saxon) XPST0003 : Left operand of '>' needs parentheses

java - 如何使用Spring以只读和读写方式进行数据库路由