SpringBoot專案打WAR包
阿新 • • 發佈:2018-12-11
預設打JAR包,如果要打WAR包,按以下步驟:
1. 改寫Application入口類
@SpringBootApplication public class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); } public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); } }
2. 在pom.xml改變此專案的打包方式
<packaging>war</packaging>
3. 在pom.xml中表明tomcat已提供,不需要內建的tomcat
<dependencies> <!-- … --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <!-- … --> </dependencies>
mvn clean package
將WAR放入TOMCAT安裝目錄的webapps, 啟動TOMCAT,訪問該web專案
http://localhost:8080/web專案