修改Springboot專案能在tomcat中執行 (jar to war)
阿新 • • 發佈:2018-12-15
0.準備工作
Springboot專案 (pom.xml <packaging>jar</packaging>)
1.新增Jar包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
2.修改pom.xml
<packaging>jar</packaging> to <packaging>war</packaging>
3.建立ServletInitializer繼承SpringBootServletInitializer
public class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(SpringbootDemoApplication.class); } } 其中SpringbootDemoApplication為SpringBootApplication