一、添加<.packaging>war</.packaging>,打包爲war包html
<packaging>war</packaging>
二、不使用SpringBoot內置的Tomcat,添加web
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
server.servlet.context-path=/MyProject
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(FileuploadApplication.class); }
修改後的啓動文件爲:spring
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); } }
mvn clean package
打包成功後,在項目的根目錄下面會多出一個target目錄,該目錄下面有一個war包,名爲:fileupload-0.0.1-SNAPSHOT.war。tomcat
注:此時訪問的端口以tomcat的端口爲準。
http://localhost:8080/MyProject/register.htmlapp