【问题标题】:Security error while modifying web.xml修改 web.xml 时出现安全错误
【发布时间】:2012-11-28 00:01:12
【问题描述】:

我是 Spring MVC 的新手,正在尝试实现 Spring Security 功能。当我修改 web.xml 文件时,Catalina 日志中出现这种错误:

27.11.2012 9:49:21 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart

web.xml 文件是:

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml /WEB-INF/spring/appServlet/security-context.xml
        </param-value>
    </context-param>
    <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>
    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>app</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/app-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>app</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>


    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.gif</url-pattern>
        <url-pattern>*.png</url-pattern>
        <url-pattern>*.js</url-pattern>
        <url-pattern>*.css</url-pattern>
    </servlet-mapping>

    <!--CharsetFilter start-->
    <filter>
        <filter-name>CharsetFilter</filter-name>
        <filter-class>kz.bimash.FoodSec.filters.CharsetFilter</filter-class>
        <init-param>
            <param-name>requestEncoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>CharsetFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list>
        <welcome-file>redirect.jsp</welcome-file>
    </welcome-file-list>
</web-app>

这段代码给了我一个错误,但是当我尝试删除 Spring Security 配置部分时,它开始正常工作。你能纠正我在web.xml 中的错误吗?

这里是 Apache 日志文件:

27.11.2012 10:57:37 org.apache.catalina.util.LifecycleBase stop
INFO: The stop() method was called on component    [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/foodsec]] after stop() had already been called. The second call will be ignored.
27.11.2012 10:57:38 org.apache.catalina.startup.HostConfig deleteRedeployResources
INFO: Undeploying context [/foodsec]
27.11.2012 10:57:38 org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor C:\Program Files\Apache Software  Foundation\tomcat7\conf\Catalina\localhost\foodsec.xml
27.11.2012 10:57:45 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
27.11.2012 10:57:45 org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/foodsec] startup failed due to previous errors

【问题讨论】:

  • SEVERE: Error listenerStart 表示你唯一的监听器(ContextLoaderListener)抛出异常或没有完成,不幸的是没有来自tomcat的足够信息我不能说发生了什么,你能从雄猫?
  • 我已经更新并编写了apache tomcat catalina日志文件,请看一下
  • 这无济于事,您在使用什么日志库?尝试记录“org.srinframework”

标签: spring apache jakarta-ee spring-mvc spring-security


【解决方案1】:

您的多个配置可能有问题:

    <param-value>/WEB-INF/spring/root-context.xml /WEB-INF/spring/appServlet/security-context.xml

尝试使用逗号代替:

    <param-value>/WEB-INF/spring/root-context.xml,/WEB-INF/spring/appServlet/security-context.xml

最佳做法是使用通配符,如下所示:

    <param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>

然后将您的上下文文件命名为:

src/main/resources/META-INF/spring/applicationContext.xml
src/main/resources/META-INF/spring/applicationContext-security.xml

【讨论】:

    【解决方案2】:

    您需要开始使用一些日志记录框架。 (将日志框架 jar 放在您的类路径中) 如果没有部署日志,没有人会帮助您(我们不想猜测)。

    看教程:http://fauzimh.wordpress.com/2011/01/26/spring-3-framework-hello-world-using-eclipse-slf4j-and-logback/

    现在在您的项目中启用 SLF4J 和 Logback。

    启用后,您应该会在 Tomcat 日志中获取有关 Spring XML 配置错误的信息。使用该信息来解决您的问题。是的,我认为问题不在于您的web.xml,而在于您的 Spring 上下文文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-27
      相关资源
      最近更新 更多