Springboot项目打war包并且部署到Tomcat7
Springboot框架自带了内置的Tomcat,通过查看依赖的jar包可以查看当前你项目版本对应的内置tomcat的版本号.
springboot版本较高的情况下,需要较高版本的jdk和tomcat才能运行起来,最近在整一个springboot项目,由于前后端没有分离,页面在工程里面.打成war包需要在tomcat7版本中,进行运行,刚刚开始的时候出现各种问题,后发现是版本兼容问题.
pom.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.techsun</groupId>
<artifactId>techsun</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging> <--配置打包-->
<name>techsun</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<start-class>com.techsun.system.WarTechsunApplication</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<!-- 移除嵌入式tomcat插件 -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 集成swagger2依赖jar包 -->
<!-- <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version> </dependency> <dependency> <groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId> <version>2.8.0</version> </dependency> -->
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<!-- <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId>
<version>2.4</version> <classifier>jdk15</classifier> </dependency> -->
<!--分页 -->
<!-- <dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.7</version>
</dependency> -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.54</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
</dependencies>
<build>
<finalName>techsun</finalName> !--配置打包的名称--<>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<!-- 仓库地址 -->
<repositories>
<repository>
<id>spring-milestone</id>
<url>http://repo.spring.io/libs-release</url>
</repository>
</repositories>
</project>
需要将springboot的版本对应的降低,我使用的是1.5.4.
二: springboot 打war包时启动类
package com.techsun.system;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
/**
* springboot项目打war包时的启动类
* @author
*
*/
@SpringBootApplication()
public class WarTechsunApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(WarTechsunApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(WarTechsunApplication.class);
}
}
三: 在pom.xml中设置启动的类 (如上面的配置文件)
四:mvn clean package
五:放入tomcat webapp 目录下,进行start.bat启动,进行地址访问即可.
还没有评论,来说两句吧...