Spring Boot is a support for releasing jar packages and wars, but it is recommended to publish using jars. Using the jar package is convenient, but if the updated item is frequently modified and needs to be patched, then a large jar package upload is a problem. Therefore, the jar package may not be suitable for all scenarios, such as a war package is more appropriate, you can try to switch to a traditional war package, so that patching package can be more convenient.
How do I Configure a war pack?
The following configuration is explained in Maven for Gradle to see similar configurations.
1. Modify Spring Boot startup class
Start the class inheritance SpringBootServletInitializer
class and override the configure
method.
The following is the sample code provided by spring boot.
@SpringBootApplicationpublic class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); } public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); }}
2. Modify Jar as war package form
In the Pom file, add the war package configuration.
<packaging>war</packaging>
If not added, the default is the jar package.
3. Remove Spring boot built-in Tomcat
Modify your own Tomcat dependency range to provided to prevent collisions with external tomcat.
<dependencies> <!-- … --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <!-- … --></dependencies>
4. Add the War package package plugin
If you're using spring boot in the form of an inherited spring-boot-starter-parent, you can skip it because it's already configured for you. If you use the dependent spring-boot-dependencies form, you need to add the following plugins.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration></plugin>
Failonmissingwebxml needs to be turned on to false, otherwise the package will report no Web. XML error.
How to fight a war bag?
There is no difference between a war package and a jar-bag approach.
After the war package was changed, it was found that it was much better to fight a war bag than to hit a jar.
What is the impact of the jar package to war package?
1, application configuration file server.xx and so on the configuration of the container is invalid, the configuration needs to be in the external tomcat.
2. Does the Spring boot upgrade require Tomcat to follow the upgrade? Need to observe.
3, Fight the war package than hit jar obviously to slow a lot.
For the time being, there are no other questions, so you can leave a comment below.
Spring boot release turns the jar package into a war package.