近段时间 做了一些前后端的开发 需要在Tomcat里进行发布 把自己整理的分享出来
pom.xml 文件
<packaging>war</packaging> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <--去掉内置的Tomcat--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> </plugin> </plugins> </build>
启动类:Application
@ServletComponentScan @SpringBootApplication
//继承SpringBootServletInitializer 类
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
//重写configure方法 @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(Application.class); } }
在终端执行命令 mvn clean package
项目刷新 会多出一个target目录
把.war的包拷贝到Tomcat的webAPP包下即可