一般情况下,spring boot项目在IDE中直接启动Application类即可启动,但生产环境肯定要部署到中间件上,比如tomcat,主要步骤如下:
1.明确打包方式为war:
在pom.xml中增加语句:<packaging>war</packaging>
2.明确tomcat相关依赖包的scope为provided:
3.修改Application启动类:
代码如下:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
@SpringBootApplication
@EnableAu