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>
server.servlet.context-path=/MyProject
@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);
}
}
mvn clean package
打包成功后,在项目的根目录下面会多出一个target目录,该目录下面有一个war包,名为:fileupload-0.0.1-SNAPSHOT.war。
注:此时访问的端口以tomcat的端口为准。
http://localhost:8080/MyProject/register.html
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。