简体   繁体   English

Netbeans / Tomcat / Jersey加载Spring上下文两次

[英]Netbeans/Tomcat/Jersey loading Spring context twice

Jersey/Spring application debugged inside Netbeans and deployed to Netbean's Tomcat server has its application context loaded twice. 在Netbeans内部调试并部署到Netbean的Tomcat服务器的Jersey / Spring应用程序将其应用程序上下文加载两次。 It is loaded, unloaded, and loaded again. 它被加载,卸载并再次加载。

BLOODY WHY?!?! 血腥为什么?!?!

EDIT: It looks like if I comment out the servlet and servlet-mapping in web.xml, the application context is still loaded twice! 编辑:看起来如果我在web.xml中注释掉servlet和servlet-mapping,应用程序上下文仍然被加载两次! If I delete /conf/web.xml file, it is STILL loaded twice. 如果我删除了/conf/web.xml文件,它将被加载两次STILL。 #@@$@! @@#$ @! Netbeans/Tomcat Netbeans的/ Tomcat的

web.xml: 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">

<servlet>
    <servlet-name>ServletAdaptor</servlet-name>
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
        <param-value>com.sun.jersey.api.container.filter.PostReplaceFilter</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>ServletAdaptor</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

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

<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
</web-app>

Tomcat output: Tomcat输出:

Using CATALINA_BASE:   "C:\Users\adubi_000\AppData\Roaming\NetBeans\7.2\apache-tomcat-7.0.27.0_base"
Using CATALINA_HOME:   "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.27"
Using CATALINA_TMPDIR: "C:\Users\adubi_000\AppData\Roaming\NetBeans\7.2\apache-tomcat-7.0.27.0_base\temp"
Using JRE_HOME:        "C:\Program Files\Java\jdk1.7.0_07"
Using CLASSPATH:       "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.27\bin\bootstrap.jar;C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.27\bin\tomcat-juli.jar"
Listening for transport dt_shmem at address: tomcat_shared_memory_id
Sep 15, 2012 9:19:22 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path:
Sep 15, 2012 9:19:22 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-80"]
Sep 15, 2012 9:19:22 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Sep 15, 2012 9:19:22 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 821 ms
Sep 15, 2012 9:19:22 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 15, 2012 9:19:22 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.27
Sep 15, 2012 9:19:22 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor C:\Users\adubi_000\AppData\Roaming\NetBeans\7.2\apache-tomcat-7.0.27.0_base\conf\Catalina\localhost\manager.xml
Sep 15, 2012 9:19:23 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor C:\Users\adubi_000\AppData\Roaming\NetBeans\7.2\apache-tomcat-7.0.27.0_base\conf\Catalina\localhost\ROOT.xml
Sep 15, 2012 9:19:26 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Sep 15, 2012 9:19:26 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Sat Sep 15 21:19:26 EST 2012]; root of context hierarchy
Sep 15, 2012 9:19:26 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
Sep 15, 2012 9:19:27 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2829abfd: defining beans [...]; root of factory hierarchy
Sep 15, 2012 9:19:28 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Sep 15, 2012 9:19:28 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.6.Final}
Sep 15, 2012 9:19:28 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Sep 15, 2012 9:19:28 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Sep 15, 2012 9:19:28 PM org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator instantiateExplicitConnectionProvider
INFO: HHH000130: Instantiating explicit connection provider: org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
Sep 15, 2012 9:19:28 PM org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure
INFO: HHH010002: C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://127.0.0.1:3306/...
Sep 15, 2012 9:19:28 PM org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure
INFO: HHH000046: Connection properties: {user=root, autocommit=true, release_mode=auto}
Sep 15, 2012 9:19:28 PM org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure
INFO: HHH000006: Autocommit mode: true
Sep 15, 2012 9:19:28 PM com.mchange.v2.log.MLog <clinit>
INFO: MLog clients using java 1.4+ standard logging.
Sep 15, 2012 9:19:28 PM com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.1 [built 16-January-2007 14:46:42; debug? true; trace: 10]
Sep 15, 2012 9:19:29 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
INFO: Initializing c3p0 pool...
Sep 15, 2012 9:19:29 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
Sep 15, 2012 9:19:29 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Sep 15, 2012 9:19:29 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
Sep 15, 2012 9:19:29 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Sep 15, 2012 9:19:29 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
...
Sep 15, 2012 9:19:31 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 4806 ms
Sep 15, 2012 9:19:31 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-80"]
Sep 15, 2012 9:19:31 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Sep 15, 2012 9:19:31 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 8866 ms
Sep 15, 2012 9:19:31 PM com.sun.jersey.spi.spring.container.servlet.SpringServlet getContext
INFO: Using default applicationContext
Sep 15, 2012 9:19:31 PM com.sun.jersey.spi.spring.container.SpringComponentProviderFactory registerSpringBeans
INFO: Registering Spring bean, ...
Sep 15, 2012 9:19:31 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.13 06/29/2012 05:14 PM'
Sep 15, 2012 9:19:32 PM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing Root WebApplicationContext: startup date [Sat Sep 15 21:19:26 EST 2012]; root of context hierarchy
Sep 15, 2012 9:19:32 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2829abfd: defining beans [...]; root of factory hierarchy
Sep 15, 2012 9:19:32 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Sep 15, 2012 9:19:32 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.
Sep 15, 2012 9:19:32 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [java-sdk-http-connection-reaper] but has failed to stop it. This is very likely to create a memory leak.
Sep 15, 2012 9:19:32 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [] created a ThreadLocal with key of type [com.sun.xml.bind.v2.ClassFactory$1] (value [com.sun.xml.bind.v2.ClassFactory$1@911a094]) and a value of type [java.util.WeakHashMap] (value [{class javax.xml.bind.annotation.W3CDomHandler=java.lang.ref.WeakReference@64455932}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Sep 15, 2012 9:19:33 PM org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context []
Sep 15, 2012 9:19:33 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor C:\Users\adubi_000\AppData\Roaming\NetBeans\7.2\apache-tomcat-7.0.27.0_base\conf\Catalina\localhost\ROOT.xml
Sep 15, 2012 9:19:36 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Sep 15, 2012 9:19:36 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Sat Sep 15 21:19:36 EST 2012]; root of context hierarchy
Sep 15, 2012 9:19:36 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
Sep 15, 2012 9:19:37 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6b63d42f: defining beans [...]; root of factory hierarchy
Sep 15, 2012 9:19:37 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Sep 15, 2012 9:19:37 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.6.Final}
Sep 15, 2012 9:19:37 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Sep 15, 2012 9:19:37 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Sep 15, 2012 9:19:38 PM org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator instantiateExplicitConnectionProvider
INFO: HHH000130: Instantiating explicit connection provider: org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
Sep 15, 2012 9:19:38 PM org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure
INFO: HHH010002: C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://127.0.0.1:3306/....
Sep 15, 2012 9:19:38 PM org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure
INFO: HHH000046: Connection properties: {user=root, autocommit=true, release_mode=auto}
Sep 15, 2012 9:19:38 PM org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure
INFO: HHH000006: Autocommit mode: true
Sep 15, 2012 9:19:38 PM com.mchange.v2.log.MLog <clinit>
INFO: MLog clients using java 1.4+ standard logging.
Sep 15, 2012 9:19:38 PM com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.1 [built 16-January-2007 14:46:42; debug? true; trace: 10]
Sep 15, 2012 9:19:38 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
INFO: Initializing c3p0 pool... 
Sep 15, 2012 9:19:38 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
Sep 15, 2012 9:19:38 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Sep 15, 2012 9:19:38 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
Sep 15, 2012 9:19:38 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Sep 15, 2012 9:19:39 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
...
Sep 15, 2012 9:19:40 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 4264 ms
Sep 15, 2012 9:19:40 PM org.apache.catalina.util.LifecycleBase start
INFO: The start() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]] after start() had already been called. The second call will be ignored.
Sep 15, 2012 9:19:41 PM com.sun.jersey.spi.spring.container.servlet.SpringServlet getContext
INFO: Using default applicationContext
Sep 15, 2012 9:19:41 PM com.sun.jersey.spi.spring.container.SpringComponentProviderFactory registerSpringBeans
INFO: Registering Spring bean, ...
Sep 15, 2012 9:19:41 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.13 06/29/2012 05:14 PM'

It is the work of Netbean's maven deploy plugin, which waits for tomcat to start (and load the application as specified in Netbeans-generared ROOT.xml) then tells it to reload it (from a different temporary XML). 这是Netbean的maven部署插件的工作,它等待tomcat启动(并按照Netbeans-generared ROOT.xml中的指定加载应用程序),然后告诉它重新加载它(来自不同的临时XML)。

A workaround is to edit %CATALINA_BASE%/conf/tomcat-users.xml and change the password of user 'ide' (through which netbeans controls tomcat). 解决方法是编辑%CATALINA_BASE%/ conf / tomcat-users.xml并更改用户'ide'的密码(netbeans控制tomcat的密码)。 Tomcat still loads fine, but deploy-on-save and probably other features won't work. Tomcat仍然可以正常加载,但部署在保存和其他功能可能无法正常工作。

I'll try looking at the source code of netbeans to see if a better solution is available. 我将尝试查看netbeans的源代码,看看是否有更好的解决方案。 This behavior of the deploy plugin is just bizare. 部署插件的这种行为只是很奇怪。 Surely it could start Tomcat empty, and then load the app as it's doing in the second step. 当然它可以启动Tomcat为空,然后在第二步中加载应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM