Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to package a spring boot project into a war package through eclipse

Shulou Source: shulou.com Published: 2022-06-02 09:01:38 09月20日 Update

This article mainly explains "how to package a spring boot project into a war package through eclipse". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to package a spring boot project into a war package through eclipse".

1. Packing

Modify the form of packaging

Set up in pom.xml

Packaging > war

Except for embedded tomcat plug-in

Find the spring-boot-starter-web dependency node in pom.xml and add the following code to it

Org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat

Add servlet-api dependency

You can do either of the following two ways, either way

Javax.servlet javax.servlet-api 3.1.0 provided

I use the following way to change the version information to the corresponding tomcat version information

Org.apache.tomcat tomcat-servlet-api 8.5.20 provided

To define the name of the project package, add the following configuration

Project name org.springframework.boot spring-boot-maven-plugin

Modify the startup class, and override the initialization method

Our method needs a configuration similar to web.xml to start the spring context, adding a SpringBootStartApplication class at the same level of the Application class with the following code:

/ * modify the startup class, inherit SpringBootServletInitializer and override the configure method * / public class SpringBootStartApplication extends SpringBootServletInitializer {public static void main (String [] args) {SpringApplication.run (SpringBootStartApplication .class, args) } / * add this method * / @ Override protected SpringApplicationBuilder configure (SpringApplicationBuilder builder) {/ / Note here to point to the Application startup class return builder.sources (SpringBootStartApplication .cl ass) that was originally executed with the main method;}}

2. Package:

Right click on the project-> run as- > maven build:

Fill in the two places shown by the arrow; then click apply- to complete the project packaging.

3. Deployment

Put the war package in the target directory under the tomcat webapps directory, start tomcat, and you can automatically extract the deployment: (under the tomcat/bi directory, double-click startup.bat to start the tomcat, start successfully, and automatically decompress the deployment to run)

4. Finally

Finally, enter it in the browser

Http://localhost:8080/[ type project name] /

Note: the port number is based on the one specified in tomcat configuration, not in springboot. The project name must be added, that is, the name of the war package, before you can access your previous request path.

Thank you for your reading, the above is the content of "how to package spring boot projects into war packages through eclipse". After the study of this article, I believe you have a deeper understanding of how to package spring boot projects into war packages through eclipse. Specific use also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Project configuration method directory learning code information content name success up and down context two slogan sibling name place that is embedded Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Redmi Huawei macOS MySQL