Tomcat 在 netbeans 中两次部署相同的应用程序 [英] Tomcat deploying the same application twice in netbeans

查看:14
本文介绍了Tomcat 在 netbeans 中两次部署相同的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NetBeansTomcat 似乎在 .war 应用程序中部署了两次,网络应用程序的两次启动.

I'm using NetBeans and Tomcat seems to be deploying in .war application twice, a double launch of the web app.

我已经尝试了 Tomcat 6 和 7 并且结果相同.

I've tried both Tomcat 6 and 7 and the same result.

我有一个 Spring MVC、Hibernate 和 Thymeleaf 应用程序.META-INF下的Context.xml有如下内容:

I've got a Spring MVC, Hibernate and Thymeleaf application. Context.xml under META-INF has the following content:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/website"/>

这是日志.

**First deployment starts**

[ INFO] 07:13:09 ContextLoader - Root WebApplicationContext: initialization started
[ INFO] 07:13:09 XmlWebApplicationContext - Refreshing Root WebApplicationContext:     startup date [Thu May 23 07:13:09 EST 2013]; root of context hierarchy
2013-05-23 07:13:10 JRebel: Monitoring Spring bean definitions in     '/Users/pack/NetBeansProjects/mysite/site/src/main/webapp/WEB-INF/applicationContext-  data.xml'.
[ INFO] 07:13:10 XmlBeanDefinitionReader - Loading XML bean definitions from     ServletContext resource [/WEB-INF/applicationContext-data.xml]
[ INFO] 07:13:10 ClassPathScanningCandidateComponentProvider - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
            ***(tomcat initializes hibernate and other spring beans)***
                                      ...
May 23, 2013 7:13:17 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 15552 ms
                                 ***Tomcat started***
                      ***Tomcat tries to shut down the context***

[ INFO] 07:13:18 XmlWebApplicationContext - Closing WebApplicationContext for namespace     'spring-mvc-servlet': startup date [Thu May 23 07:13:15 EST 2013]; parent: Root WebApplicationContext
[ INFO] 07:13:18 DefaultListableBeanFactory - Destroying singletons in  org.springframework.beans.factory.support.DefaultListableBeanFactory@5bbe2de2: defining beans    [blHeadProcessor,blHeadProcessorExtensionManager,navigationProcessor,blPaginationPageLinkPro cessor,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,blRegisterCustomerValidator,blCategoryController,com.package.ui.thymeleaf.CategoryHandlerMapping#0,templateResolver,templateEngine,org.thymeleaf.spring3.view.ThymeleafViewResolver#0,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; parent:   org.springframework.beans.factory.support.DefaultListableBeanFactory@521e7f21
[ INFO] 07:13:18 XmlWebApplicationContext - Closing Root WebApplicationContext: startup  date [Thu May 23 07:13:09 EST 2013]; root of context hierarchy 
[ INFO] 07:13:18 DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@521e7f21: defining beans    [org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0,blCategoryDao,blCustomerDao,blIdGenerationDao,nlpDao,jpaTemplate,webDS,entityManagerFactory,transactionManager,org.springframework.security.filterChains,org.springframework.security.filterChainProxy,org.springframework.security.web.DefaultSecurityFilterChain#0,org.springframework.security.web.DefaultSecurityFilterChain#1,org.springframework.security.web.DefaultSecurityFilterChain#2,org.springframework.security.web.DefaultSecurityFilterChain#3,org.springframework.security.web.DefaultSecurityFilterChain#4,org.springframework.security.web.DefaultSecurityFilterChain#5,org.springframework.security.web.PortMapperImpl#0,org.springframework.security.web.PortResolverImpl#0,org.springframework.security.authentication.ProviderManager#0,org.springframework.security.web.context.HttpSessionSecurityContextRepository#0,org.springframework.security.web.savedrequest.HttpSessionRequestCache#0,org.springframework.security.web.access.channel.ChannelDecisionManagerImpl#0,org.springframework.security.access.vote.AffirmativeBased#0,org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0,org.springframework.security.web.access.DefaultWebInvocationPrivilegeEvaluator#0,org.springframework.security.authentication.AnonymousAuthenticationProvider#0,org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0,org.springframework.security.userDetailsServiceFactory,org.springframework.security.web.DefaultSecurityFilterChain#6,org.springframework.security.authentication.dao.DaoAuthenticationProvider#0,org.springframework.security.authentication.DefaultAuthenticationEventPublisher#0,org.springframework.security.authenticationManager,blUserDetailsService,blCatalogService,blCustomerService,entityService,fbPageService,blIdGenerationService,blLoginService,nlpService,priceIncreaseValidator,searchFacetService,blEntityConfiguration,blPasswordEncoder,solrIndexService,solrEmbedded,textEncryptor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
[ INFO] 07:13:18 LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'blPU'
[ INFO] 07:13:18 SessionFactoryImpl - closing
May 23, 2013 7:13:18 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/website] 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.
May 23, 2013 7:13:19 AM org.apache.catalina.startup.HostConfig deleteRedeployResources
INFO: Undeploying context [/website]
May 23, 2013 7:13:19 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /Users/pack/Servers/apache-tomcat- 7.0.34/conf/Catalina/localhost/website.xml
2013-05-23 07:13:23 JRebel: Monitoring Log4j configuration in   'file:/Users/pack/NetBeansProjects/mysite/site/target/mycompany/WEB-INF/classes/log4j.xml'.

                          ***Tomcat tries to restart again***

[ INFO] 07:13:23 ContextLoader - Root WebApplicationContext: initialization started
[ INFO] 07:13:23 XmlWebApplicationContext - Refreshing Root WebApplicationContext:   startup date [Thu May 23 07:13:23 EST 2013]; root of context hierarchy
2013-05-23 07:13:24 JRebel: Monitoring Spring bean definitions in   '/Users/pack/NetBeansProjects/mysite/site/src/main/webapp/WEB-INF/applicationContext-  data.xml'.
[ INFO] 07:13:24 XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext-data.xml]

并成功启动.

我不明白的是为什么 Tomcat 会两次部署应用程序.我第一次在新的 tomcat 实例上部署应用程序时不会发生这种情况,因为 website.xml 文件不在 tomcats/conf/catalina/localhost 文件夹中.但是当我再次从 netbeans 停止并运行 tomcat 时,website.xml 文件仍在/conf/catalina/localhost 文件夹中,但在第二次部署即将发生之前被删除并重新部署.

What I don't understand is why is Tomcat is deploying the application twice. This does not occur the first time I deploy the application on a new tomcat instance because the website.xml file is not in tomcats /conf/catalina/localhost folder yet. But when I stop and run tomcat from netbeans again the website.xml file is still in the /conf/catalina/localhost folder but get deleted and re-deployed just before the second deployment is about to happen.

我尝试将 Tomcat 的 server.xml 文件中的 autoDeploy 设置为 false,但没有帮助.

I've tried setting autoDeploy in server.xml file of Tomcat to false but it didn't help.

<Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="false">

可能是 Tomcat 应该在每次 tomcat 停止时删除/conf/catalina/localhost 文件夹下的 website.xml 文件.

May be Tomcat should be deleting the website.xml file under /conf/catalina/localhost folder everytime tomcat stops.

这是localhost文件夹下的website.xml文件的样子

This is how website.xml file under localhost folder looks like

<?xml version="1.0" encoding="UTF-8"?>
<Context
    docBase="/Users/pack/NetBeansProjects/mysite/site/target/mycompany"  
    path="/website"
/>

推荐答案

我发现删除文件 conf/localhost/myappname.xml 会阻止应用程序初始化两次.基本上 Tomcat 正在重新启动,并重新启动旧版本的应用程序.然后当 Netbeans 部署它时它会再次启动.作为一种解决方法,我在 ContextListener contextDestroyed() 事件中添加了几行代码:

I found that deleting the file conf/localhost/myappname.xml prevents the app from initializing twice. Basically Tomcat is restarting, and restarting the old version of your app. Then it starts again when Netbeans deploys it. As a workaround, I added a few lines of code in my ContextListener contextDestroyed() event:

public void contextDestroyed(ServletContextEvent sce) {
...
String delme = sce.getServletContext().getInitParameter("eraseOnExit");
if (delme != null && delme.length() > 0) {
    File del = new File(delme);
    if (del.exists()) {
        System.out.println("Deleting file " + delme);
        del.delete();
    }
}

在 web.xml 中,在开发环境中添加以下内容:

In the web.xml add the following in a dev environment:

<context-param>
    <description>Workaround for Tomcat starting webapp twice</description>
    <param-name>eraseOnExit</param-name>
    <param-value>/Users/xxx/apache-tomcat-7.0.42/conf/Catalina/localhost/myappname.xml</param-value>
</context-param>

然后下次部署应用程序时,它不会在部署之前再次启动,因此不会启动两次.在部署之前或关闭时删除文件的任何其他想法将不胜感激.

Then the next time the app is deployed, it won't be started again prior to the deployment, hence will not start twice. Any other ideas for deleting a file prior to deploying, or on shutdown, would be appreciated.

这篇关于Tomcat 在 netbeans 中两次部署相同的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆