SpringBoot項目部署到tomcat
阿新 • • 發佈:2019-01-16
添加 打包成 servle 測試 f2c vpd framework public eba SpringBoot部署到tomcat
一、修改maven.xml
1、添加<.packaging>war</.packaging>,打包為war包
<packaging>war</packaging>
2、不使用SpringBoot內置的Tomcat,添加
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
二、修改application.properties文件,添加 content-path
server.servlet.context-path=/MyProject
三、修改啟動文件main方法,讓該方法繼承自SpringBootServletInitializer,並且重寫configure方法:
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(FileuploadApplication.class); }
修改後的啟動文件為:
package qiu.fileupload; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication public class FileuploadApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(FileuploadApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(FileuploadApplication.class); } }
四、打包
1、在項目的根目錄下面執行命令:
mvn clean package
打包成功後,在項目的根目錄下面會多出一個target目錄,該目錄下面有一個war包,名為:fileupload-0.0.1-SNAPSHOT.war。
2、將fileupload-0.0.1-SNAPSHOT.war改名為yml文件中context-path的名字MyProject
五、拷貝到tomcat的webapps目錄,重啟tomcat。
六、訪問測試
註:此時訪問的端口以tomcat的端口為準。
http://localhost:8080/MyProject/register.html
SpringBoot項目部署到tomcat