当前位置:   article > 正文

Springboot项目以war包形式发布到tomcat流程及问题_tomcat springboot war包

tomcat springboot war包

由于项目需求,所以两个项目需要放到同一个tomcat中,且端口号相同。

一、springboot打war包

1.pom.xml文件配置

1.添加war包

<packaging>war</packaging>

2.添加排除内置tomcat依赖

  1. <!--排除tomcat-->
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-tomcat</artifactId>
  5. <scope>provided</scope>
  6. </dependency>

3.添加war包依赖以设置名称

  1. <build>
  2. <!--war包名称-->
  3. <finalName>${project.artifactId}</finalName>
  4. <plugins>
  5. <!--对项目打war包依赖-->
  6. <plugin>
  7. <groupId>org.apache.maven.plugins</groupId>
  8. <artifactId>maven-war-plugin</artifactId>
  9. <version>3.0.0</version>
  10. <configuration>
  11. <failOnMissingWebXml>false</failOnMissingWebXml>
  12. </configuration>
  13. </plugin>
  14. </plugins>
  15. </build>

2.启动类配置

1.继承SpringBootServletInitializer类,重写configure方法

  1. @SpringBootApplication(scanBasePackages = "com.hdro")
  2. @EnableTransactionManagement //事务
  3. public class HdxxcjProApplication extends SpringBootServletInitializer {
  4. public static void main(String[] args) {
  5. SpringApplication.run(HdxxcjProApplication.class, args);
  6. }
  7. @Override
  8. protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
  9. return builder.sources(HdxxcjProApplication.class);
  10. }
  11. }

3.项目发布

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时,出现如下错误

  1. 03-Jan-2024 15:13:27.614 严重 [Catalina-startStop-1] org.apache.catalina.core.ContainerBase.startInternal 子容器启动失败
  2. java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: 无法启动组件[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/hdxxcjPro]]
  3. at java.util.concurrent.FutureTask.report(FutureTask.java:122)
  4. at java.util.concurrent.FutureTask.get(FutureTask.java:188)
  5. at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:892)
  6. at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:793)
  7. at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
  8. at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1362)
  9. at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1352)
  10. at java.util.concurrent.FutureTask.run(FutureTask.java:262)
  11. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  12. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  13. at java.lang.Thread.run(Thread.java:745)
  14. Caused by: org.apache.catalina.LifecycleException: 无法启动组件[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/hdxxcjPro]]
  15. at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
  16. at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
  17. ... 6 more
  18. Caused by: java.lang.UnsupportedClassVersionError: org/springframework/web/SpringServletContainerInitializer : Unsupported major.minor version 52.0 (无法载入的类 [org.springframework.web.SpringServletContainerInitializer])
  19. at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2481)
  20. at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:881)
  21. at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1384)
  22. at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1228)
  23. at java.lang.Class.forName0(Native Method)
  24. at java.lang.Class.forName(Class.java:278)
  25. at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:241)
  26. at org.apache.catalina.startup.WebappServiceLoader.load(WebappServiceLoader.java:212)
  27. at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1590)
  28. at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1089)
  29. at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:780)
  30. at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:300)
  31. at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
  32. at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4855)
  33. at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
  34. ... 6 more
  35. 03-Jan-2024 15:13:28.808 严重 [main] org.apache.catalina.core.ContainerBase.startInternal 子容器启动失败
  36. java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: 子容器启动失败
  37. at java.util.concurrent.FutureTask.report(FutureTask.java:122)
  38. at java.util.concurrent.FutureTask.get(FutureTask.java:188)

结合网上的信息,发现时jdk版本问题,之前装的是jdk1.7,但springboot项目用的是jdk1.8,所以启动报错,出现闪退情况。把本地版本更新为1.8,问题消失,tomcat启动正常。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/146923?site
推荐阅读
相关标签
  

闽ICP备14008679号