设置打包类型和打包名称
<packaging>war</packaging>
<finalName>springboot-deploy</finalName>
<?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 https://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>2.0.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>springboot-deploy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-deploy</name>
<description>springboot-deploy</description>
<properties>
<java.version>1.8</java.version>
</properties>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<finalName>springboot-deploy</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
springboot 入口文件继承SpringBootServletInitializer类重写configure设置tomcat访问入口
@SpringBootApplication
public class SpringbootDeployApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(SpringbootDeployApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(SpringbootDeployApplication.class);
}
}
1.然后将其war包JavaWebTest.war复制粘贴到apache-tomcat-8.5\webapps\目录下(个人习惯,另外的目录理应也可以)
2、配置apache-tomcat-8.5\conf\server.xml文件
并找到<Host>节点添加下面的代码,如下:
<Context path="/car" docBase="C:\Users\Admin\Desktop\apache-tomcat-8.5.54\webapps\ROOT\JavaWebTest.war" reloadable="true"></Context>
3.访问路径:http://localhost:8080/car/