Spring boot release turns the jar package into a war package.

Source: Internet
Author: User

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.

    • Use the commands in Maven to mvn clean package package.

    • In idea, you can set up a package like this:

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.