How the Spring boot project launches the web in eclipse

Source: Internet
Author: User
Tags port number tomcat

Description
The Spring boot framework was recently started, and spring boot came with a servlet container, discovering that, in addition to running the project in Java mode, the Application.java was deployed in a way that would normally be used to launch a Web project to spring Boot's built-in servlet container, to launch the Spring-boot project as it was published in the same way as a normal Web project under Tomcat, needs to be configured in Eclipse.

Specific Steps

(1). Modify Pom.xml to change the packaging method to war

      <packaging>war</packaging>

(2). Version support for Tomcat

    <!--to join this when fighting a war package, tell Spring-boot Tomcat about the outside of the jar pack, do not punch in--
<dependency>
    <groupId> Org.springframework.boot</groupid>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

Add this, without spring-boot the built-in Tomcat library

(3). Modify the Startup class and override the initialization method

  We need a configuration similar to Web. XML to start the spring context, add a springbootstartapplication class to the application class, with the following code:
/**
 * Modify Startup class, Inherit Springbootservletinitializer and override Configure method
 */Public
class Springbootstartapplication Extends Springbootservletinitializer {

    @Override  
    protected Springapplicationbuilder Configure ( Springapplicationbuilder application) {  
        return application.sources (Application.class);  
    }

}

(4). This allows the Spring-boot project to be launched in Eclipse in the same way that a normal Web project is posted to tomcat (recommended to be released to root)

Note: Enter the project root directory (that is, the directory containing the Pom.xml), open the command line and enter it at the command line:
MVN clean packages, waiting to be packaged, the [INFO] BUILD success is packaged successfully.
Then put the war package in the target directory under Tomcat's WebApps directory and launch Tomcat to automatically unzip the deployment.
Finally, enter in the browser

http://localhost:[port number/[Package project name]/
Related Article

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.