After the Spring Boot project is developed, it can be deployed to the server in two ways:

  • Jar packages (official recommendation)
  • War file

The JAR package uses the built-in Tomcat, while the WAR package packages the project to run on external Tomcat.

Let’s take a look at the directory structure of the demo project:

Start by introducing web dependencies in the POM.xml file, which has a built-in default Tomcat server; And configure the port number in application.properties:

pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
Copy the code

application.properties

# Application service WEB access port
server.port=8080
Copy the code

Then write a Controller that can handle the request (for packaged validation) :

@RestController
@RequestMapping("/hello")
public class HelloController {

    @RequestMapping("/jar")
    public String jarDeploy(a) {
        return "Successfully JAR the SpringBoot project!"; }}Copy the code

Then click Package to package the project:

To start the project, run the following command: java-jar.\deploy-0.0.1- snapshot. jar

That’s the end of jar package deployment; The WAR package (minor) won’t be covered here.

We hope this article will help you 🧠 feel free to leave your thoughts in the comments 🌊, we will discuss and share 🔥