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