In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to solve the problems encountered when the SpringBoot project is packaged and released to the external tomcat". The editor shows you the operation process through an actual case, the method of operation is simple and fast, and it is practical. I hope that this article "how to solve the problems encountered when the SpringBoot project is packaged and released to the external tomcat" can help you solve the problem.
First of all, let's talk about the situation where there is a problem:
The first attempt to use the spring boot framework to write a small web project, in Intellij IDEA can start and run normally. Run install with maven, generate a war package, publish it to the local tomcat, and an exception occurs. The main exception message is .LifeCycleException. After various searches, the answer was found.
Because spring boot has an embedded tomcat container, you can publish a project by packaging it as a jar package, but how do you package a spring boot project into a war package project that can be published into tomcat?
1. Since you need to package into a war package project, you first need to modify the package type in the pom.xml file to change the default jar of spring boot to war form.
two。 Secondly, the tomcat server is embedded in spring boot's web project, so if we want to publish warp packages to tomcat projects, we need to exclude the tomcat package dependencies embedded in spring boot, otherwise there is a conflict, just open the comments in the following code.
Org.springframework.boot spring-boot-starter-web
One thing I want to say is that if you still want to use spring boot embedded tomcat for debugging when developing locally, you can add the following dependencies
Org.springframework.boot spring-boot-starter-tomcat provided
3. Spring boot publishes the jar package the entry of the web program is the class where the main function is located, using the @ SpringBootApplication annotation. But if the war package is published to tomcat, you need to add the SpringBootServletInitializer subclass and override its configure method, or directly inherit the main function's class from the SpringBootServletInitializer subclass and override its configure method. Examples of the code are as follows
SpringBootApplicationpublic class DemoApplication extends SpringBootServletInitializer {@ Override protected SpringApplicationBuilder configure (SpringApplicationBuilder application) {return application.sources (DemoApplication.class);} public static void main (String [] args) {SpringApplication.run (DemoApplication.class, args);}}
The above completes all the steps of packaging the war package for the spring boot project, which can be released to tomcat7 and above.
Last but not least, if your native tomcat version is not consistent with the 8.0 version of springboot automatic integration. There will also be problems and solutions:
My local Tomcat version is 8.0.28, while the Tomcat on the server is 7.0.69. I made a local Tomcat7.0.70 deployment and reported the same error. It is more certain that the problem is related to the Tomcat version. After searching for information from many parties, I finally saw a foreigner on Stackoverflow saying that SpringBoot's default Servlet container is based on Tomcat8.
It is true that the Tomcat-related war package was found in the typed jar package, and it belongs to Tomcat8. Take Tomcat8's embed bag under Tomcat7. It must not work.
To support a lower version of Tomcat, you need to specify the Tomat version in maven, as follows:
7.0.69
Then add it to the dependency (you don't have to add this, the official document is added)
Org.apache.tomcat tomcat-juli ${tomcat.version}
Plus I tried it later, and sure enough, there was no problem. After looking at the lib directory in the war package, it has indeed become a Tomcat7 package.
But I am still a little confused, this configuration into a package is not to change the Tomcat version of the need to re-package? Since this restriction is caused by the Servlet container inside SpringBoot, can I not use it? I have checked a lot of information, and there is really a way!
This is the end of org.springframework.boot spring-boot-starter-tomcat provided's content on "how to solve the problems encountered in packaging and publishing SpringBoot projects to external tomcat". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.