Springboot项目打war包并且部署到Tomcat7

古城微笑少年丶 2022-03-06 09:18 616阅读 0赞

Springboot框架自带了内置的Tomcat,通过查看依赖的jar包可以查看当前你项目版本对应的内置tomcat的版本号.

20190318163814927.png

springboot版本较高的情况下,需要较高版本的jdk和tomcat才能运行起来,最近在整一个springboot项目,由于前后端没有分离,页面在工程里面.打成war包需要在tomcat7版本中,进行运行,刚刚开始的时候出现各种问题,后发现是版本兼容问题.

pom.xml如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>1.5.4.RELEASE</version>
  9. <relativePath /> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.techsun</groupId>
  12. <artifactId>techsun</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <packaging>war</packaging> <--配置打包-->
  15. <name>techsun</name>
  16. <description>Demo project for Spring Boot</description>
  17. <properties>
  18. <java.version>1.8</java.version>
  19. <start-class>com.techsun.system.WarTechsunApplication</start-class>
  20. </properties>
  21. <dependencies>
  22. <dependency>
  23. <groupId>org.springframework.boot</groupId>
  24. <artifactId>spring-boot-starter-web</artifactId>
  25. <exclusions>
  26. <exclusion>
  27. <groupId>org.springframework.boot</groupId>
  28. <artifactId>spring-boot-starter-logging</artifactId>
  29. </exclusion>
  30. <!-- 移除嵌入式tomcat插件 -->
  31. <exclusion>
  32. <groupId>org.springframework.boot</groupId>
  33. <artifactId>spring-boot-starter-tomcat</artifactId>
  34. </exclusion>
  35. </exclusions>
  36. </dependency>
  37. <!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId>
  38. </dependency> -->
  39. <dependency>
  40. <groupId>org.mybatis.spring.boot</groupId>
  41. <artifactId>mybatis-spring-boot-starter</artifactId>
  42. <version>1.1.1</version>
  43. </dependency>
  44. <dependency>
  45. <groupId>mysql</groupId>
  46. <artifactId>mysql-connector-java</artifactId>
  47. <scope>runtime</scope>
  48. </dependency>
  49. <dependency>
  50. <groupId>org.springframework.boot</groupId>
  51. <artifactId>spring-boot-starter-tomcat</artifactId>
  52. <scope>provided</scope>
  53. </dependency>
  54. <dependency>
  55. <groupId>org.springframework.boot</groupId>
  56. <artifactId>spring-boot-starter-test</artifactId>
  57. <scope>test</scope>
  58. </dependency>
  59. <!-- 集成swagger2依赖jar包 -->
  60. <!-- <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId>
  61. <version>2.8.0</version> </dependency> <dependency> <groupId>io.springfox</groupId>
  62. <artifactId>springfox-swagger-ui</artifactId> <version>2.8.0</version> </dependency> -->
  63. <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
  64. <dependency>
  65. <groupId>org.apache.commons</groupId>
  66. <artifactId>commons-lang3</artifactId>
  67. <version>3.4</version>
  68. </dependency>
  69. <!-- <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId>
  70. <version>2.4</version> <classifier>jdk15</classifier> </dependency> -->
  71. <!--分页 -->
  72. <!-- <dependency>
  73. <groupId>com.github.pagehelper</groupId>
  74. <artifactId>pagehelper-spring-boot-starter</artifactId>
  75. <version>1.2.7</version>
  76. </dependency> -->
  77. <dependency>
  78. <groupId>com.github.pagehelper</groupId>
  79. <artifactId>pagehelper</artifactId>
  80. <version>5.1.4</version>
  81. </dependency>
  82. <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
  83. <dependency>
  84. <groupId>com.alibaba</groupId>
  85. <artifactId>fastjson</artifactId>
  86. <version>1.2.54</version>
  87. </dependency>
  88. <dependency>
  89. <groupId>org.springframework.boot</groupId>
  90. <artifactId>spring-boot-starter-log4j2</artifactId>
  91. </dependency>
  92. </dependencies>
  93. <build>
  94. <finalName>techsun</finalName> !--配置打包的名称--<>
  95. <plugins>
  96. <plugin>
  97. <groupId>org.springframework.boot</groupId>
  98. <artifactId>spring-boot-maven-plugin</artifactId>
  99. </plugin>
  100. <plugin>
  101. <groupId>org.apache.maven.plugins</groupId>
  102. <artifactId>maven-war-plugin</artifactId>
  103. <version>2.6</version>
  104. <configuration>
  105. <failOnMissingWebXml>false</failOnMissingWebXml>
  106. </configuration>
  107. </plugin>
  108. </plugins>
  109. </build>
  110. <!-- 仓库地址 -->
  111. <repositories>
  112. <repository>
  113. <id>spring-milestone</id>
  114. <url>http://repo.spring.io/libs-release</url>
  115. </repository>
  116. </repositories>
  117. </project>

需要将springboot的版本对应的降低,我使用的是1.5.4.

二: springboot 打war包时启动类

  1. package com.techsun.system;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.boot.builder.SpringApplicationBuilder;
  5. import org.springframework.boot.web.support.SpringBootServletInitializer;
  6. /**
  7. * springboot项目打war包时的启动类
  8. * @author
  9. *
  10. */
  11. @SpringBootApplication()
  12. public class WarTechsunApplication extends SpringBootServletInitializer {
  13. public static void main(String[] args) {
  14. SpringApplication.run(WarTechsunApplication.class, args);
  15. }
  16. @Override
  17. protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
  18. return builder.sources(WarTechsunApplication.class);
  19. }
  20. }

三: 在pom.xml中设置启动的类 (如上面的配置文件)


1.8
com.techsun.system.WarTechsunApplication

四:mvn clean package

五:放入tomcat webapp 目录下,进行start.bat启动,进行地址访问即可.

发表评论

表情:
评论列表 (有 0 条评论,616人围观)

还没有评论,来说两句吧...

相关阅读