Tomcat同时部署多个war文件

今天遇到一个问题,要在一个tomcat中部署多个war文件,在此之前对tomcat的了解就是,默认配置下,在webapp文件夹下新建的文件夹即可通过ip+端口+文件夹名 被访问到,所以多个war包直接扔里就应该是没问题,但是:
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)

at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)

at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)

at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)

at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)

at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

at java.util.concurrent.FutureTask.run(FutureTask.java:266)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at java.lang.Thread.run(Thread.java:748)

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userTransactionService' defined in class path resource [org/springframework/boot/autoconfigure/transaction/jta/AtomikosJtaConfiguration.class]: Invocation of init method failed; nested exception is com.atomikos.icatch.SysException: Error in init: Log already in use? tmlog in D:\A_long\apache-tomcat-8.5.34\bin\transaction-logs\

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)

at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)

at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742)

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)

at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:151)

at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:131)

at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:91)

at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:171)

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

... 10 more

Caused by: com.atomikos.icatch.SysException: Error in init: Log already in use? tmlog in D:\A_long\apache-tomcat-8.5.34\bin\transaction-logs\

at com.atomikos.icatch.provider.imp.AssemblerImp.createRepository(AssemblerImp.java:181)

at com.atomikos.icatch.provider.imp.AssemblerImp.assembleTransactionService(AssemblerImp.java:156)

at com.atomikos.icatch.config.Configuration.assembleSystemComponents(Configuration.java:485)

at com.atomikos.icatch.config.Configuration.init(Configuration.java:448)

at com.atomikos.icatch.config.UserTransactionServiceImp.initialize(UserTransactionServiceImp.java:105)

at com.atomikos.icatch.config.UserTransactionServiceImp.init(UserTransactionServiceImp.java:219)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1904)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1846)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774)

... 29 more

Caused by: com.atomikos.recovery.LogException: Log already in use? tmlog in D:\A_long\apache-tomcat-8.5.34\bin\transaction-logs\

at com.atomikos.persistence.imp.LogFileLock.acquireLock(LogFileLock.java:59)

at com.atomikos.recovery.imp.FileSystemRepository.init(FileSystemRepository.java:55)

at com.atomikos.icatch.provider.imp.AssemblerImp.createCoordinatorLogEntryRepository(AssemblerImp.java:229)

at com.atomikos.icatch.provider.imp.AssemblerImp.createRepository(AssemblerImp.java:179)

... 41 more

16-Jul-2020 21:16:00.169 严重 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive [D:\A_long\apache-tomcat-8.5.34\webapps\XHPiano_2020.war]

java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/XHPiano_2020]]

at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:758)

at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)

at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)

at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)

at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

at java.util.concurrent.FutureTask.run(FutureTask.java:266)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at java.lang.Thread.run(Thread.java:748),

经过查询才知道,如果多个springboot项目,都通过atomikos配置了多数据源,在同一服务器主机上启动运行,就会报错:

com.atomikos.recovery.LogException: Log already in use? 

出错原因:atomikos默认日志打印:tomcat\transaction-logs\tmlog.lck  和  tomcat\transaction-logs\tmlog0.log,导致多项目共用同一日志文件,前面的项目将会锁定文件,后面启动的项目将会无法写入。所以解决方案就有了,既然是公用同一个日志文件导致的,那就自己用自己的不就好了,修改文件名称或路径,或者干脆不用日志,于是乎,解决方案就是:

1.在配置文件中修改日志文件名称,一个项目一个不重复,spring.jta.atomikos.properties.log-base-name=name1(name2,name3.。。)

2.在配置文件中修改日志文件路径,一个项目一个不重复,spring.jta.atomikos.properties.log-base-dir=./log/name1(./log/name2,name3..)

3.在配置文件中关闭日志打印(可以开一个),spring.jta.atomikos.properties.enable-logging=false

以上参考的是:https://blog.csdn.net/wtl1992/article/details/90766815

你可能感兴趣的:(Tomcat同时部署多个war文件)