springboot 用war包部署
由jar变成war
pom.xml:<packaging>jar</packaging>
如果是上面的打包方式,启动方式则为
mvn package
java -jar target/mymodule-0.0.1-SNAPSHOT.jar
改变成war
pom.xml:<packaging>war</packaging>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
如果要发布到外部的tomcat同时需要改变启动方式
新增ServletInitializer类
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
Application.class 为标注有@SpringBootApplication的主启动类
评论
发表评论
|
|