Springboot Deploying the war package to external Tomcat

Source: Internet
Author: User

Tagged with: War Web package name ROM support packages for package project www. Packaged

Springboot Application default packaging becomes the executable jar mode, which gives us a sense of ease of deployment, and then introduces you to the Springboot project as a war package deployed to external Tomcat.

Modify an existing project

1. Modify the project

Open the project and modify the Pom file:
1. Add Spring-boot-starter-web to the project (if it is already joined to the dependent project can be ignored) and spring-boot-starter-tomcat dependent.
2.packaging modified by Jar to war.
3. Add Finalname in Build, this is set to fight the war package name, can not be set using the default.

The complete pom file is as follows:

? xml Version=1.0encoding=utf-8?

Project xmlns=http://maven.apache.org/pom/4.0.0 Xmlns:xsi=http://www.w3.org/2001/xmlschema-instance

xsi:schemalocation=http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd

Modelversion4.0.0/modelversion

Groupidcom.dalaoyang/groupid

Artifactidspringboot_tomcat/artifactid

Version0.0.1-snapshot/version

Packagingwar/packaging

Namespringboot_tomcat/name

Descriptionspringboot_tomcat/description

Parent

Groupidorg.springframework.boot/groupid

Artifactidspring-boot-starter-parent/artifactid

Version1.5.15.release/version

relativepath/!--Lookup Parent from repository--

/parent

Properties

Project.build.sourceencodingutf-8/project.build.sourceencoding

Project.reporting.outputencodingutf-8/project.reporting.outputencoding

Java.version1.8/java.version

/properties

Dependencies

Dependency

Groupidorg.springframework.boot/groupid

Artifactidspring-boot-starter-web/artifactid

/dependency

Dependency

Groupidorg.springframework.boot/groupid

Artifactidspring-boot-devtools/artifactid

Scoperuntime/scope

/dependency

Dependency

Groupidorg.springframework.boot/groupid

Artifactidspring-boot-starter-tomcat/artifactid

Scopeprovided/scope

/dependency

Dependency

Groupidorg.springframework.boot/groupid

Artifactidspring-boot-starter-test/artifactid

Scopetest/scope

/dependency

/dependencies

Build

Plugins

Plugin

Groupidorg.springframework.boot/groupid

Artifactidspring-boot-maven-plugin/artifactid

/plugin

/plugins

Finalnamespringboot_tomcat/finalname

/build

/project

Modify the startup class so that it inherits from the Springbootservletinitializer class, overriding the Configure method, with the following code:

Package Com.dalaoyang;

Import org.springframework.boot.SpringApplication;

Import org.springframework.boot.autoconfigure.SpringBootApplication;

Import Org.springframework.boot.builder.SpringApplicationBuilder;

Import Org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication

public class Springboottomcatapplication extends Springbootservletinitializer {

public static void Main (string[] args) {

Springapplication.run (Springboottomcatapplication.class, args);

}

@Override

Protected Springapplicationbuilder Configure (Springapplicationbuilder application) {

Return application.sources (Springboottomcatapplication.class);

}

}

Create a new controller, as a test, with the following code:

Package Com.dalaoyang;

Import org.springframework.web.bind.annotation.GetMapping;

Import Org.springframework.web.bind.annotation.RestController;

/**

* @author Dalaoyang

* @project Springboot_learn

* @package Com.dalaoyang

* @email [email protected]

* @date 2018/8/1

*/

@RestController

public class Controller {

@GetMapping (/)

Public String Index () {

return Hello, Dalaoyang;

}

}

Startup Project, local access to http://localhost:8080/,

Packaged deployment

Next we just need to package the project into the Tomcat test, this article takes the idea packaging as an example, double-click the package,

Watch the console and wait for the package to complete.

Copy the war package into Tomcat's WebApp directory and run Tomcat,,tomcat boot successfully (note that the Tomcat port does not conflict with the current boot port).

Using a browser to access http://localhost:8080/springboot_tomcat/, the result:

Create a new project directly in the form of a war.

New Project

Modify packaging to War,

Dependency only joins a web dependency,

Next to the end, then open the project discovery, select War mode has automatically integrated the Spring-boot-starter-tomcat dependency for us, And already for a new servletinitializer automatically inherit the Springbootservletinitializer and rewrite the configure, thanks to our powerful IDE, test and the above is the same can be successful.

?

Springboot Deploying the war package to external Tomcat

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.