当前位置: 首页 > 知识库问答 >
问题:

Tomcat在netbeans中两次部署同一个应用程序

弘承运
2023-03-14
<?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]
<Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="false">

可能是Tomcat每次停止都要删除/conf/catalina/localhost文件夹下的website.xml文件。

localhost文件夹下的website.xml文件如下所示

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

共有1个答案

鱼旺
2023-03-14

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

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中,在开发环境中添加以下内容:

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

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

 类似资料:
  • 我试图用netbeans和Tomcat8部署java应用程序。单击debug时,在“Apache Tomcat或Tomee”选项卡中出现异常: 用netbeans和Tomcat进行部署还有另一种方法吗?我不想总是用Sudo从控制台运行netbeans。

  • 我有一个部署在tomcat上的应用程序,并且正在运行。Tomcat安装在unix操作系统上。我想部署一个相同应用程序的另一个副本(几乎没有代码更改,相同的应用程序名称)到同一个tomcat实例,在不同的端口上运行。是否可以在tomcat的同一个实例上使用不同的端口运行相同的应用程序。是否在单个jvm上运行单个tomcat实例?。如果是这样,那么会出现什么问题? 提前谢谢

  • 每次我尝试在netbeans上部署web应用程序时,都会出现以下错误:\ C: \Users{myname}\Documents\NetBeansProjects\WebApplication2\nbproject\build impl。xml:1045:模块尚未部署。有关详细信息,请参阅服务器日志。 问题是,apache日志中没有错误! 我已经卸载了我的netbean并重新安装它,但问题仍然存在

  • 我试图在tomcat 6中部署一个Spring引导应用程序(战争)(当在tomcat 7和更旧的版本中部署时,我没有问题),事实上在tomcat 6(servlet 2.5)中部署是不可能使用新的方式(我会把描述新方式的链接放在底部),因为Spring Boot使用Servet 3.0 API初始化ServletContext(注册Servlet等),所以您不能在Servlet 2.5容器中开箱即

  • 完成干净的构建后,我将war文件复制到Tomcat的文件夹中。但是部署会发生两次,并且在上下文已经存在的情况下以异常结束。我错过了什么? 非常感谢您的帮助。

  • 问题内容: 我们已经开发了JEE5 Web应用程序(WAR),并在WebLogic 11g(10.3.5)下在生产环境中运行它。 现在,应将同一应用程序部署为同一WebLogic上针对不同客户(不同URL,不同数据)的单独应用程序。 我通过在部署每个上下文根后设置不同的上下文根来管理第一部分。 但是我还没有使它们使用不同的数据源- 并且由于我想避免使用特定于客户的版本,因此persistence.