Spring Web 应用程序初始化了两次

2023-12-22

我发现我的 spring web 项目在 tomcat 上初始化了两次,下面是打印的消息

第一次:

 INFO: Initializing Spring root WebApplicationContext
 INFO 2015-01-08 15:18:04 ContextLoader Root WebApplicationContext: initialization started 
 INFO 2015-01-08 15:18:04 XmlWebApplicationContext Refreshing Root WebApplicationContext: startup date [Thu Jan 08 15:18:04 GMT+08:00 2015]; root of context hierarchy 
 INFO 2015-01-08 15:18:04 XmlBeanDefinitionReader Loading XML bean definitions from file [/home/pinkdahlia/develop/apache-tomcat-7.0.55/webapps/vips-mobile-mlisting-backend/WEB-INF/classes/spring-shiro.xml] 
 INFO 2015-01-08 15:18:04 XmlBeanDefinition Reader Loading XML bean definitions from file [/home/pinkdahlia/develop/apache-tomcat-7.0.55/webapps/vips-mobile-mlisting-backend/WEB-INF/classes/spring-datasources.xml] 
 INFO 2015-01-08 15:18:04 XmlBeanDefinitionReader Loading XML bean definitions from file [/home/pinkdahlia/develop/apache-tomcat-7.0.55/webapps/vips-mobile-mlisting-backend/WEB-INF/classes/spring-commons.xml] 
 INFO 2015-01-08 15:18:05 XmlBeanDefinitionReader Loading XML bean definitions from file [/home/pinkdahlia/develop/apache-tomcat-7.0.55/webapps/vips-mobile-mlisting-backend/WEB-INF/classes/spring-mybatis.xml] 
 INFO 2015-01-08 15:18:05 XmlBeanDefinitionReader Loading XML bean definitions from file [/home/pinkdahlia/develop/apache-tomcat-7.0.55/webapps/vips-mobile-mlisting-backend/WEB-INF/classes/spring-xmemcached.xml] 
 INFO 2015-01-08 15:18:05 XmlBeanDefinitionReader Loading XML bean definitions from file [/home/pinkdahlia/develop/apache-tomcat-7.0.55/webapps/vips-mobile-mlisting-backend/WEB-INF/classes/spring-aop.xml] 
 INFO 2015-01-08 15:18:05 PropertiesFactoryBean Loading properties file from URL [file:/home/pinkdahlia/develop/config/BackendConf.properties]

第二次:

 INFO: Initializing Spring root WebApplicationContext
 INFO 2015-01-08 15:18:13 ContextLoader Root WebApplicationContext: initialization started 
 INFO 2015-01-08 15:18:13 XmlWebApplicationContext Refreshing Root WebApplicationContext: startup date [Thu Jan 08 15:18:13 GMT+08:00 2015]; root of context hierarchy 
 INFO 2015-01-08 15:18:13 XmlBeanDefinitionReader Loading XML bean definitions from file [/home/pinkdahlia/develop/apache-tomcat-7.0.55/webapps/vips-mobile-mlisting-backend/WEB-INF/classes/spring-shiro.xml] 
 INFO 2015-01-08 15:18:13 XmlBeanDefinitionReader Loading XML bean definitions from file [/home/pinkdahlia/develop/apache-tomcat-7.0.55/webapps/vips-mobile-mlisting-backend/WEB-INF/classes/spring-datasources.xml] 
 INFO 2015-01-08 15:18:13 XmlBeanDefinitionReader Loading XML bean definitions from file [/home/pinkdahlia/develop/apache-tomcat-7.0.55/webapps/vips-mobile-mlisting-backend/WEB-INF/classes/spring-commons.xml] 
 INFO 2015-01-08 15:18:13 XmlBeanDefinitionReader Loading XML bean definitions from file [/home/pinkdahlia/develop/apache-tomcat-7.0.55/webapps/vips-mobile-mlisting-backend/WEB-INF/classes/spring-mybatis.xml] 
 INFO 2015-01-08 15:18:13 XmlBeanDefinitionReader Loading XML bean definitions from file [/home/pinkdahlia/develop/apache-tomcat-7.0.55/webapps/vips-mobile-mlisting-backend/WEB-INF/classes/spring-xmemcached.xml] 
 INFO 2015-01-08 15:18:13 XmlBeanDefinitionReader Loading XML bean definitions from file [/home/pinkdahlia/develop/apache-tomcat-7.0.55/webapps/vips-mobile-mlisting-backend/WEB-INF/classes/spring-aop.xml] 
 INFO 2015-01-08 15:18:14 PropertiesFactoryBean Loading properties file from URL [file:/home/pinkdahlia/develop/config/BackendConf.properties] 

这是我的 web.xml 中的内容:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
         version="3.0"
         metadata-complete="true">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath*:spring-*.xml
        </param-value>
    </context-param>

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:log4j.properties</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

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

    <servlet>
        <servlet-name>mvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>mvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    </web-app>

最后是我的 mvc-servlet.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
                       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
                       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <aop:config proxy-target-class="true"></aop:config>

    <context:property-placeholder location="file:${vips.backend.config}"/>

    <context:component-scan base-package="com.vip.mlisting" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
    </context:component-scan>

    <mvc:annotation-driven>
        <mvc:argument-resolvers>
            <bean class="com.vip.mlisting.system.resolver.CurrentUserMethodArgumentResolver"/>
        </mvc:argument-resolvers>
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

        <mvc:resources mapping="/static/**" location="/WEB-INF/static/"/>

    <!-- the prefix and suffix of ViewResolver -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:order="1">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="contentType" value="text/html"/>
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"></bean>
</beans>

我已经尽力在谷歌上找到解决方案,但没有任何效果,任何人都可以帮助,非常感谢。


这是因为 2 个上下文

servlet-level spring context

and

global Spring context common to the whole application

在你的 web.xml 中

<servlet>
    <servlet-name>mvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

也可以看看为什么 Spring MVC 至少需要两个上下文? https://stackoverflow.com/questions/18682486/why-does-spring-mvc-need-at-least-two-contexts Spring MVC Web 应用程序:应用程序上下文启动两次 https://stackoverflow.com/questions/15951257/spring-mvc-web-app-application-context-starts-twice

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring Web 应用程序初始化了两次 的相关文章

随机推荐

  • Enter 因隐藏按钮而无法在 IE 中提交表单

    我有一个带有两个按钮的表单 第一个是使用 Javascript 隐藏的 当我在 IE 中的文本字段中按 Enter 键时 表单不会提交 我认为这是因为它选择了第一个按钮作为默认提交按钮 但由于该按钮被隐藏 因此它不起作用 我通过在 Ente
  • 如何在 matlab 中使用 theta/rho 数据绘制直线

    如题 我只有 theta rho 数据 直线方程为 x cos theta y sin theta rho 如何在matlab中用这些数据绘制线 有没有输入为 theta 和 rho 的函数 thanks 只需使用一些简单的代数即可了解如何
  • 如何在询问槽后捕获IBM Watson Assistant中一个实体的多个值?

    在我的 Watson Assistant 应用程序中 我想要捕获上下文中的多个实体 并且还有一个槽位来向用户提问 这是一个例子 用户 我想从 多伦多 飞往 波士顿 Watson 正确检测到 intent booking city Toron
  • jQuery 摆脱嵌套的 ajax 函数

    在我的JS中 我需要使用AJAX获取3个文件的内容 然后执行一些代码 这导致了嵌套异步函数的创建看起来相当奇怪 另外 每当我使用异步函数时 就会出现这种丑陋的嵌套 当我真的只想等待每个函数完成时 如何避免嵌套函数 如果有帮助的话我正在使用
  • 如何自动启动、执行和停止EC2?

    我想每天在 GPU 机器上测试一次我的 Python 库 我决定使用AWS EC2进行测试 但是gpu机器的费用很高 所以我想在测试结束后停止实例 因此 我想每天自动执行以下操作一次 启动 EC2 实例 手动设置 执行命令 测试 gt 将日
  • 在 VSCode 扩展中找不到命令

    我正在尝试创建 VSCode 扩展 这个扩展提供了两个命令 不用管它们的实现 export function activate context ExtensionContext const provider new ContentProvi
  • 如何对用户密码进行哈希处理?

    请不要将其标记为重复 因为我已经检查了多个帖子 但没有一个对我有帮助 Asp net MVC 如何哈希密码 https stackoverflow com questions 39802164 asp net mvc how to hash
  • 日期无效时引发错误

    我想做的是在日期超出支持范围的情况下引发超出范围错误 就像类型转换所做的那样 我在 CentOS 上使用 PostgreSQL 9 1 6 问题如下 postgres select to date 20130229 yyyymmdd to
  • 如何展平 Observable 中的 Observable 数组

    我正在尝试展平嵌套的 Observable 但我没有让它工作 this af object test father map res gt res namedKeys for let el in res keys res namedKeys
  • 为什么不建议在头文件中定义宏?

    The 谷歌 C 风格指南 http google github io styleguide cppguide html Preprocessor Macros指南建议宏不得定义在 h 头 文件 这样做有什么坏处 预处理器将所有包含的源文件
  • C# 文件大小限制

    我有一个使用 ASP NET NET 2 0 构建的网站 我的业务逻辑中有很多类 我将它们全部保存在一个文件 BL cs 中 我现在已经到了这个文件中有 11 000 行代码的阶段 这是一个问题吗 我应该将其分成几个文件 每个类位于不同的文
  • Ruby:带有 JSON 主体的 PUT 请求?

    我需要创建一个HTTP PUT 请求使用红宝石 该请求有一个JSON 正文 我能够使用以下方法生成 JSON 正文 require rubygems require json jsonbody JSON generate message g
  • html/css 中的楼梯步进文本

    是否有使用 HTML CSS 在网站上阶梯式文本的最佳实践方法 这个单词 and https i stack imgur com eEMe5 png说明了效果 使用CSS属性vertical align带有百分比值 参见MDN 上的此部分
  • 为什么使用 Typescript - Angular2 进行类型定义 (.d.ts)?

    我已经看过其他SO问题了 但仍然对我的问题感到困惑 我见过很多使用的例子Jquery js Toastr js 无需打字的烤面包机 http plnkr co edit VEMcA3SnYtQ35GzVgt80 p preview和别的JS
  • 使用 BouncyCastle 进行简单的 HTTPS 查询

    下面是我用来执行简单 HTTPS 请求的代码的简化版本 Assume the variables host file and postData have valid String values final URL url new URL h
  • 当软键盘出现时,Edittext 在横向模式下调整大小

    当我处于横向模式且屏幕上有 EditText 时 如果我点击 EditText 以调出软键盘 则 EditText 会在两个维度上展开 以占据未被键盘占用的整个屏幕 当键盘关闭时 它会恢复正常大小 我检查了手机上的其他商业应用程序 其中许多
  • 实现接口方法时不允许使用@Override

    我遇到了标题中提到的问题 你可以说这个线程重复了另一个线程 如何在 IntelliJ IDEA 中关闭注释的错误验证 https stackoverflow com questions 1525947 how do i turn off e
  • Flutter @Error:此库禁用空安全功能

    我正在构建一个 Flutter 应用程序 当我为 Android 构建应用程序时 该应用程序运行良好 但当我开始为 iOS 构建应用程序时 我开始遇到 此库禁用空安全功能 的错误 错误如下 Users himanshu pub cache
  • CSS 中的 Rem 单位大小

    我对 CSS 中的 rem 单位有疑问 在我当前的项目中 所有尺寸都是 rem 当我设置元素大小 如 div 时 显示的大小为 16 px x ems 但当 div 包含文本或标题时 显示的大小为 19 x ems Chrome FF 和
  • Spring Web 应用程序初始化了两次

    我发现我的 spring web 项目在 tomcat 上初始化了两次 下面是打印的消息 第一次 INFO Initializing Spring root WebApplicationContext INFO 2015 01 08 15