以下是本人在intelij idea下打包spring boot项目的步骤
1.修改pom.xml
1.1 把打包类型换成war包
<packaging>war</packaging>
1.2 配置外部tomcat(此段代码在本地运行需注释掉)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
2.修改启动类Application.java
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
public static void main(String[] args) {
Application.run(Application.class, args);
}
}
3.maven打包,先执行clean,再install,最后package,看到控制台显示“BUILD SUCCESS”即表示成功
4. 在target目录下把生成的war包拷到tomcat的webapps目录下,重启tomcat服务即可
5.输入http://ip:port/项目名/接口名 即可测试接口