赞
踩
由于项目需求,所以两个项目需要放到同一个tomcat中,且端口号相同。
1.添加war包
<packaging>war</packaging>
2.添加排除内置tomcat依赖
- <!--排除tomcat-->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-tomcat</artifactId>
- <scope>provided</scope>
- </dependency>
3.添加war包依赖以设置名称
- <build>
- <!--war包名称-->
- <finalName>${project.artifactId}</finalName>
- <plugins>
- <!--对项目打war包依赖-->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-war-plugin</artifactId>
- <version>3.0.0</version>
- <configuration>
- <failOnMissingWebXml>false</failOnMissingWebXml>
- </configuration>
- </plugin>
-
- </plugins>
- </build>
1.继承SpringBootServletInitializer类,重写configure方法
- @SpringBootApplication(scanBasePackages = "com.hdro")
- @EnableTransactionManagement //事务
- public class HdxxcjProApplication extends SpringBootServletInitializer {
-
- public static void main(String[] args) {
- SpringApplication.run(HdxxcjProApplication.class, args);
- }
-
- @Override
- protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
- return builder.sources(HdxxcjProApplication.class);
- }
- }
1.运行命令(在idea中,或者doc窗口都可以),打war包
mvn clean install
出现 BUILD SUCCESS 表示成功
2.复制war包,将war包放到tomcat->webapps中,并配置项目访问路径(conf->server.xml文件中)
<Context path="/xaxxcj" docBase="xaxxcj" reloadable="true" debug="0">
综上,启动项目 bin->startup.bat
启动tomcat时,出现如下错误
- 03-Jan-2024 15:13:27.614 严重 [Catalina-startStop-1] org.apache.catalina.core.ContainerBase.startInternal 子容器启动失败
- java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: 无法启动组件[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/hdxxcjPro]]
- at java.util.concurrent.FutureTask.report(FutureTask.java:122)
- at java.util.concurrent.FutureTask.get(FutureTask.java:188)
- at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:892)
- at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:793)
- at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
- at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1362)
- at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1352)
- at java.util.concurrent.FutureTask.run(FutureTask.java:262)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
- at java.lang.Thread.run(Thread.java:745)
- Caused by: org.apache.catalina.LifecycleException: 无法启动组件[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/hdxxcjPro]]
- at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
- at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
- ... 6 more
- Caused by: java.lang.UnsupportedClassVersionError: org/springframework/web/SpringServletContainerInitializer : Unsupported major.minor version 52.0 (无法载入的类 [org.springframework.web.SpringServletContainerInitializer])
- at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2481)
- at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:881)
- at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1384)
- at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1228)
- at java.lang.Class.forName0(Native Method)
- at java.lang.Class.forName(Class.java:278)
- at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:241)
- at org.apache.catalina.startup.WebappServiceLoader.load(WebappServiceLoader.java:212)
- at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1590)
- at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1089)
- at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:780)
- at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:300)
- at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
- at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4855)
- at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
- ... 6 more
- 03-Jan-2024 15:13:28.808 严重 [main] org.apache.catalina.core.ContainerBase.startInternal 子容器启动失败
- java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: 子容器启动失败
- at java.util.concurrent.FutureTask.report(FutureTask.java:122)
- at java.util.concurrent.FutureTask.get(FutureTask.java:188)
结合网上的信息,发现时jdk版本问题,之前装的是jdk1.7,但springboot项目用的是jdk1.8,所以启动报错,出现闪退情况。把本地版本更新为1.8,问题消失,tomcat启动正常。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。