The springboot microservice has built-in tomcat, which is executed in the project directory: mvn clean package, and the project can be started by using java -jar jar package name.jar.
What scenarios do you need to deploy springboot as a war package?
1. One tomcat manages multiple projects
2.Springboot integrates jsp, etc.
Solution:
1. Change the jar in <packaging>jar</packaging> 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 dependencies--> <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. The startup class inherits SpringBootServletInitializer and overrides the 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 tag:
<context> to <context xmlblockexternal="false">, you can package and deploy</context></context>
Summarize
The above is the tutorial and solution for mobile development Spring Boot external tomcat introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!