Spring applicationContext(不是servlet context)加载了两次

时间:2016-05-23 21:48:43

标签: spring

我创建了spring config,其中applicationContext包含所有'重'bean和 servlet上下文只有控制器。我的问题是所有'大'bean的applicationContext被加载两次。我做错了什么?

我看了thisthis但没有帮助:

我的web.xml

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

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

<servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-conf/dispatcher.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

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

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

的applicationContext.xml

<context:annotation-config/>

<context:component-scan base-package="kkl.server.error" />
<context:component-scan base-package="kkl.server.services" />
<context:component-scan base-package="kkl.server.log" />
<context:component-scan base-package="kkl.server.model" />
<context:component-scan base-package="kkl.server.security" />
<context:component-scan base-package="kkl.server.utils" />
<context:component-scan base-package="kkl.server.validation" />



<!-- ///////////////// properties ///////////////////// -->

<context:property-placeholder
    location="classpath:spring-conf/properties/application.properties"
    order='0' ignore-resource-not-found="false" />
<context:property-placeholder
    location="classpath:spring-conf/properties/local.properties" order='-1'
    ignore-unresolvable='true' ignore-resource-not-found="true"/>

<import resource="classpath:spring-conf/spring-aop_and_transactions.xml" />
<import resource="classpath:spring-conf/spring-security.xml" />
<import resource="classpath:spring-conf/spring-database.xml" />

dispatcher.xml

<context:annotation-config />

<mvc:annotation-driven>
    <mvc:message-converters>
        <bean
            class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
            <property name="objectMapper">
                <bean class="kkl.fireRpg.server.controllers.utils.json.JsonObjectMapper" />
            </property>
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>


<!-- ///////////////// scanned packages //////////////////// -->
<context:component-scan base-package="kkl.server.controllers" />

更新

当我在applicationContext和web.xml中注释每个东西(没有listener和context-param)之后,我的tomcat输出看起来像这样:

`maj 24, 2016 1:13:54 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:firerpg' did not find a matching property.
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/8.0.18
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Jan 23 2015 11:56:07 UTC
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         8.0.18.0
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 7
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            6.1
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          x86
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             C:\Program Files (x86)\Java\jdk1.8.0_60\jre
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_60-b27
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18\webapps
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18\endorsed
maj 24, 2016 1:13:54 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
maj 24, 2016 1:13:54 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jdk1.8.0_60\jre\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre1.8.0_60/bin/client;C:/Program Files (x86)/Java/jre1.8.0_60/bin;C:/Program Files (x86)/Java/jre1.8.0_60/lib/i386;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Bitvise SSH Client;D:\programy\java\apache-maven-3.3.9\bin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;D:\programy\java\eclipseluna\eclipse;;.
maj 24, 2016 1:13:55 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
maj 24, 2016 1:13:55 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
maj 24, 2016 1:13:55 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
maj 24, 2016 1:13:55 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
maj 24, 2016 1:13:55 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 676 ms
maj 24, 2016 1:13:55 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
maj 24, 2016 1:13:55 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.18
maj 24, 2016 1:13:59 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
maj 24, 2016 1:13:59 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
maj 24, 2016 1:13:59 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
maj 24, 2016 1:13:59 AM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Tue May 24 01:13:59 CEST 2016]; root of context hierarchy
maj 24, 2016 1:13:59 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring-conf/applicationContext.xml]
maj 24, 2016 1:13:59 AM org.springframework.context.support.PropertySourcesPlaceholderConfigurer loadProperties
INFO: Loading properties file from class path resource [spring-conf/properties/local.properties]
maj 24, 2016 1:13:59 AM org.springframework.context.support.PropertySourcesPlaceholderConfigurer loadProperties
INFO: Loading properties file from class path resource [spring-conf/properties/application.properties]
maj 24, 2016 1:13:59 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 655 ms
maj 24, 2016 1:14:00 AM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [265] milliseconds.
maj 24, 2016 1:14:00 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18\webapps\docs
maj 24, 2016 1:14:00 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18\webapps\docs has finished in 31 ms
maj 24, 2016 1:14:00 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18\webapps\examples
maj 24, 2016 1:14:00 AM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
maj 24, 2016 1:14:00 AM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
maj 24, 2016 1:14:00 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18\webapps\examples has finished in 375 ms
maj 24, 2016 1:14:00 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18\webapps\firerpg
maj 24, 2016 1:14:03 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
maj 24, 2016 1:14:03 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
maj 24, 2016 1:14:03 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
maj 24, 2016 1:14:04 AM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Tue May 24 01:14:04 CEST 2016]; root of context hierarchy
maj 24, 2016 1:14:04 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring-conf/applicationContext.xml]
maj 24, 2016 1:14:04 AM org.springframework.context.support.PropertySourcesPlaceholderConfigurer loadProperties
INFO: Loading properties file from class path resource [spring-conf/properties/local.properties]
maj 24, 2016 1:14:04 AM org.springframework.context.support.PropertySourcesPlaceholderConfigurer loadProperties
INFO: Loading properties file from class path resource [spring-conf/properties/application.properties]
maj 24, 2016 1:14:04 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 561 ms
maj 24, 2016 1:14:04 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18\webapps\firerpg has finished in 3,932 ms
maj 24, 2016 1:14:04 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18\webapps\host-manager
maj 24, 2016 1:14:04 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18\webapps\host-manager has finished in 16 ms
maj 24, 2016 1:14:04 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18\webapps\manager
maj 24, 2016 1:14:04 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18\webapps\manager has finished in 16 ms
maj 24, 2016 1:14:04 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18\webapps\ROOT
maj 24, 2016 1:14:04 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory D:\programy\java\apache-tomcat-8.0.18-windows-x86\apache-tomcat-8.0.18\webapps\ROOT has finished in 15 ms
maj 24, 2016 1:14:04 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
maj 24, 2016 1:14:04 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
maj 24, 2016 1:14:04 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 9413 ms`

这一行:

INFO: Loading XML bean definitions from class path resource [spring-   conf/applicationContext.xml]

显示两次。

1 个答案:

答案 0 :(得分:0)

我对这个问题打了很多。我几乎禁用了所有东西,但它仍然存在。 然后我回到我的eclipse tomcat配置,我设置'使用真实安装'。 当我将设置更改为使用“使用工作区元数据”后问题消失。

我正在使用 eclipse luna release 2 tomcat 8

我希望这可以节省时间。

<强>更新

经过几次尝试后,我发现eclipse正在破坏我的tomcat安装。 (我尝试了一个新的确保)。当我设置'使用真正的安装'时 问题再次发生。在此之后,即使我在没有eclipse的情况下运行tomcat,它仍然存在。

解决方案是:删除你的tomcat安装。设置一个新的并且永远不会改变'使用工作空间元数据'