Spring Boot项目部署到tomcat启动失败404
1、现象
控制台没有springboot加载日志,访问localhost:port/project 404
2、原因分析
tomcat没有加载到该项目
3、解决方案
3.1、在pom.xml文件中,把打包形式jar改为war
<packaging>war</packaging>
3.2、在pom中添加一条依赖,屏蔽springboot中tomcat容器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
3.3、修改启动类SpringbootApplication继承SpringBootServletInitializer
public class SpringbootApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
}
//重写configure方法
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(SpringbootApplication.class);
}
}
4、打包部署
eclipse中修改项目为
Dymanic Web Module,java, javascript
Deployment Assembly--->Add--->Java Build Path Entries--->Maven Dependencies
mvn clean package