Spring Boot war package instance tutorial, springwar

Source: Internet
Author: User

Spring Boot war package instance tutorial, springwar

In addition to executable jar packages, Spring Boot also supports traditional war packages. This article describes how to use Spring Boot to build a traditional war package.

Follow these steps to create a war package for Spring Boot:

1. Define the packaging type in pom. xml

<packaging>war</packaging>

2. Add the Spring Boot starter (you can also use parent)

  <dependencyManagement> <dependencies>  <dependency>  <!-- Import dependency management from Spring Boot -->  <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-dependencies</artifactId>  <version>1.5.6.RELEASE</version>  <type>pom</type>  <scope>import</scope>  </dependency> </dependencies> </dependencyManagement>

3. Add spring-boot-starter-web dependency

    <dependency>  <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-starter-web</artifactId>  <exclusions>  <exclusion>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-starter-tomcat</artifactId>  </exclusion>  </exclusions> </dependency>

4. Add packaging plug-ins

  <build> <plugins>  <plugin>  <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-maven-plugin</artifactId>  </plugin> </plugins> </build>

5. The main class inherits SpringBootServletInitializer

/** * WAR application */@SpringBootApplicationpublic class WarApplication extends SpringBootServletInitializer {  public static void main(String[] args) { SpringApplication.run(WarApplication.class, args); }}

6. Run mvn clean package to package

$mvn clean package

7. Copy the prepared war package to a container (such as tomcat) and run it.

Here we need to briefly describe:

The main application can rewrite SpringBootServletInitializer with the configure method to customize Spring Boot configuration.

  /** * Configure the application. Normally all you would need to do is to add sources * (e.g. config classes) because other settings have sensible defaults. You might * choose (for instance) to add default command line arguments, or set an active * Spring profile. * @param builder a builder for the application context * @return the application builder * @see SpringApplicationBuilder */ protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder; }

Download instance source code

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.