Spring Boot project to deploy to tomcat failed to start 404

1, a phenomenon

  Springboot console does not load logs, access localhost: port / project 404

2, Analysis

  tomcat is not loaded into the project

3, solutions

  3.1, in the pom.xml file, packaged in the form of the jar instead war

<packaging>war</packaging>

  3.2, was added in a dependency pom, the shielding container springboot in tomcat

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
</dependency>

  3.3, modify the startup class SpringbootApplication inherit 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, package deployment

  modify the project to eclipse

  Dymanic Web Module,java, javascript

  Deployment Assembly--->Add--->Java Build Path Entries--->Maven Dependencies

mvn clean package

 

Guess you like

Origin www.cnblogs.com/51ma/p/11313553.html