Springboot Project Fight War Package deployment Tomcat Tutorial

Source: Internet
Author: User

First, Introduction

Normally the Springboot project is started directly with a jar package, using its internal tomcat to implement MicroServices, but there may be a need to deploy to external Tomcat, and this tutorial explains how to do it.

Ii. Modification of Pom.xml

Set the Pom.xml file <packaging> node for the module to be deployed to the war

<!---<packaging>war</Packaging  >

It is possible to pack when you are prompted to find Maven-war-plugin. Add the following configuration to the <plugins> node in the Pom.xml

< plugin >    < Artifactid >maven-war-plugin</artifactid>    <version  >3.2.0</version></plugin >

Third, modify the main () method start class

Inherit the Springbootservletinitializer base class to initialize the Springboot, rewrite the Configure method inside and inject yourself in

Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.SpringBootApplication;Importorg.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;ImportOrg.springframework.boot.builder.SpringApplicationBuilder;ImportOrg.springframework.boot.web.servlet.support.SpringBootServletInitializer;ImportOrg.springframework.context.annotation.ComponentScan; @ComponentScan ("Com.ysl.ts")//scan packages for common modules@SpringBootApplication (exclude = datasourceautoconfiguration.class)//Inherit the war package Springboot initialize the base class Public classWebbaseappextendsSpringbootservletinitializer {//overriding the configuration method@OverrideprotectedSpringapplicationbuilder Configure (Springapplicationbuilder application) {returnApplication.sources (Webbaseapp.class); }     Public Static voidMain (string[] args) {Springapplication.run (Webbaseapp.class, args); }}

Iv. disabling JMX internal bean monitoring (optional)

If there is a reference to a module in the war that we deploy, and the bean in this module has the following error, the two war registers the same bean.

Org.springframework.jmx.export.UnableToRegisterMBeanException:Unable to register MBean

Add the following configuration to disable JMX internal monitoring in Application.properties

Spring.jmx.enabled=false

V. Appendix Tomcat Installation

Download Tomcat Address: http://tomcat.apache.org/

Unzip to the specified directory: C:\apache-tomcat-8.5.33

1. Add Environment variables
variable Name: Catalina_home variable Value: C:\apache-tomcat-8.5.33Path added:%catalina_home%\bin
2. Enter the Tomcat directory and enter the bin to run Startup.bat (if you have a flashback, check that the environment variable is configured correctly)

Open the browser http://localhost:8080 you can see, as on behalf of the successful launch

3. Configuration Administrator

Open the Tomcat directory, enter the Conf directory, open the Tomcat-users.xml, you can add the following users, or the default comment is also OK, save the restart, close the Startup.bat window and then perform Shutdown.bat completely shut Tomcat before booting

<!--<role rolename= "Tomcat"/> <role rolename= "role1"/> <user username= "Tomcat" password= "< Must-be-changed> "roles=" Tomcat "/> <user username=" Both "password=" <must-be-changed> "roles=" Tomcat, Role1 "/> <user username=" role1 "password=" <must-be-changed> "roles=" Role1 "/> -<rolerolename= "Manager-gui"/><Userusername= "Admin"Password=""Roles= "Manager-gui"/>

Click on the Manager app to enter the admin password empty OK to enter, on behalf of the administrator configuration completed

4. Deploy the site

Put your war in a position and remember the path.

Open the Tomcat directory, enter the Conf directory, open Server.xml, and locate the host node to add the following nodes inside it

Path: Access to directory such as http://localhost:8080/ysl_web/

DocBase: The site War directory, which can be a relative path or an absolute path, will automatically decompress the war package and place it in the Tomcat WebApps directory

<path= "/ysl_web"  docBase= "d:/travelsupport/website/ Ysl-ts-web-base-1.0-snapshot.war "  debug=" 0 "  privileged=" true "  reloadable= "true"/>

Restart Tomcat, if the error is in the Tomcat logs directory to view the log, start success, click on the manager App, click/ysl_web to see your site

Springboot Project Fight War Package deployment Tomcat Tutorial

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.