1. 程式人生 > >SpringBoot2.0打成war包,部署到Tomcat伺服器

SpringBoot2.0打成war包,部署到Tomcat伺服器

①將maven打包方式改為war

<packaging>war</packaging>

②在pom檔案中引入依賴

<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>javax.servlet-api</artifactId>
	<scope>provided</scope>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-tomcat</artifactId>
	<scope>provided</scope>
</dependency>

③在啟動類的同級目錄下新建一個類

public class ServletInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(啟動類.class);
    }
}

然後就可以maven install了,將war包放到tomcat下,啟動就可以訪問了。埠就是tomcat的埠,訪問地址預設要帶有你的war包名稱