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);
}
}
1.在项目的根目录下面执行命令:
mvn clean package
打包成功后,在项目的根目录下面会多出一个target目录,该目录下面有一个war包,名为:fileupload-0.0.1-SNAPSHOT.war。
2.将fileupload-0.0.1-SNAPSHOT.war改名为yml文件中context-path的名字MyProject
注:此时访问的端口以tomcat的端口为准。
http://localhost:8080/MyProject/register.html
动力节点在线课程涵盖零基础入门,高级进阶,在职提升三大主力内容,覆盖Java从入门到就业提升的全体系学习内容。全部Java视频教程免费观看,相关学习资料免费下载!对于火爆技术,每周一定时更新!如果想了解更多相关技术,可以到动力节点在线免费观看SpringBoot基础教程哦!
代码小兵87208-09 15:04
代码小兵99203-29 17:29
杨晶珍08-02 11:09
代码小兵98808-09 14:38
代码小兵28608-09 14:50