在 Tomcat 上安装基于 spring 的应用程序

Posted

技术标签:

【中文标题】在 Tomcat 上安装基于 spring 的应用程序【英文标题】:Install spring based application on Tomcat 【发布时间】:2012-08-04 18:33:01 【问题描述】:

我已经在 ROOT 和管理上下文中安装了应用程序。这两个应用程序都是在 Spring Framework 3.1.2 和 Maven 结构上创建的。当我尝试运行应用程序时出现错误:

Aug 7, 2012 5:20:54 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet  threw load() exception
java.lang.ClassNotFoundException: org.springframework.web.context.support.StandardServletEnvironment
    (...)
INFO: Initializing Spring root WebApplicationContext
Aug 7, 2012 5:21:08 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter springSecurityFilterChain
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
    (...)

我的类路径中有 spring-web。我的 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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:root-context.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>
            org.springframework.web.context.request.RequestContextListener
        </listener-class>
    </listener>
    <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>
    <filter>
        <filter-name>SetCharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>SetCharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter>
        <filter-name>hibernateFilter</filter-name>
        <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>hibernateFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <error-page>
        <error-code>404</error-code>
        <location>/error/404.html</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/error/500.html</location>
    </error-page>
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
</web-app>

我该如何解决这个问题?

【问题讨论】:

【参考方案1】:

在您的应用程序上下文中(或通过注释),您没有使用名称 springSecurityFilterChain 定义的 bean。

【讨论】:

我从未听说过在 bean 中定义的 springSecurityFilterChain。你能告诉我我该怎么做吗? 您将阅读有关 Spring 的内容。 Spring bean 就像学习 Spring 的第一步。任何在线教程都会讨论它们。 当然。但是 springSecurityFilterChain 是 Spring 上下文中的默认 bean,所以我不应该定义他。我想真正的问题在于 org.springframework.web.context.support.StandardServletEnvironment,但我找不到有关它的信息。 它没有在 web.xml 文件中定义,它将在您的 servlet 上下文或根上下文文件中定义。 好的,我做。我现在只有 StandardServletEnvironment 错误。

以上是关于在 Tomcat 上安装基于 spring 的应用程序的主要内容,如果未能解决你的问题,请参考以下文章

在本地 tomcat 上运行的 Spring Boot 应用程序在 Elastic Beanstalk 上提供 404

如何在运行在 Tomcat 上的 Spring Web 应用程序中使用 Spring 的响应式 WebClient

如何在 Jboss 或 Tomcat 上部署 Spring Cloud Gateway 2.1?

基于 Spring Boot (Tomcat) 的应用程序作为守护进程 - 如何停止?

访问没有斜杠的 Tomcat 应用程序时,Spring Security Context 为空

如何在没有完整安装 Tomcat 的情况下运行 Spring Web 应用程序?