Mobile development Spring Boot External tomcat tutorial and solutions
- 2020-11-25 07:15:21
- OfStack
springboot microservice has tomcat built in and is executed in the project directory :mvn clean package. You can call the project jar and start the project with java-ES8en jar package name.jar.
What scenarios do you need to package springboot as war for deployment?
1.1 tomcat managed multiple projects
2.springboot integrated jsp, etc
Solutions:
1. < packaging > jar < /packaging > Change jar to war
2. Introduce dependencies:
<dependency>
<groupid>org.springframework.boot</groupid>
spring-boot-starter-web</artifactid>
<exclusions>
<exclusion>
<groupid>org.springframework.boot</groupid>
spring-boot-starter-tomcat</artifactid>
</exclusion>
</exclusions>
</dependency>
<!--servlet Rely on -->
<dependency>
<groupid>javax.servlet</groupid>
javax.servlet-api</artifactid>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupid>org.apache.tomcat</groupid>
tomcat-servlet-api</artifactid>
<version>8.0.36</version>
<scope>provided</scope>
</dependency>
3. Start class to inherit SpringBootServletInitializer, and override configure method:
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure
(SpringApplicationBuilder builder) {
return builder.sources(DemoApplication.class);
}
</code></code>
}
4. Modify the tomcat configuration file context.xml
Modify the label:
<context> to <context xmlblockexternal="false"> , you can package and deploy
</context></context>
conclusion