springboot applications running in the tomcat

1 are packaged into the WAR, because if it is java -jar xx.jarrun, it must be jar package

 <packaging>war</packaging>

2. Add rely tomcat, but pay attention to the scope (scope)

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

3. Configure JavaBean, is to inherit SpringBootInitializer class, override the configure method

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringBootApplication.class);
    }

}

4. tomcat8 above, experience: with tomcat7 and below, will be reported the following error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path

Guess you like

Origin www.cnblogs.com/Lyn4ever/p/11495048.html