Home  >  Article  >  Java  >  How to quickly build a springboot project

How to quickly build a springboot project

WBOY
WBOYforward
2023-05-13 15:49:224302browse

1. Empty Project

Now most of the development process is based on the idea integrated development environment. The author was very stubborn before and always used eclipse. Later, the company needed to switch to idea. I have to say that idea is indeed It’s easy to use, friends who have never used it can try it. Here, idea is used as the demonstration environment.

I usually start with an empty project, File-->New-->Project in idea, as shown on the left side of the picture below

How to quickly build a springboot project

## Select Maven and select JDK on the right. The "Create from archetype" below represents choosing a pom template. I am building an empty project here, so I don't choose it. Unless you are particularly sure, don't choose it. There will be unexpected surprises.

Look at the next step,

How to quickly build a springboot project

Write the project name. Here you can see that the project name and ArtifactId are the same, or they can be different. It is best to be the same. Oh, click "Finish" to complete the creation. The built project is as follows,

How to quickly build a springboot project

You can see that the basic structure of a maven project is already there. Let's start the springboot journey. .

2. Start the springboot journey

Now development is all springboot web projects, which means that the service exists in the form of embedded tomcat, then we need to introduce dependencies,

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.3.3.RELEASE</version>
    </dependency>

That is, add the above dependencies to the pom. You also need a startup class before,

package com.my.template;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//springboot的启动注解
@SpringBootApplication
public class BootServer {
    public static void main(String[] args) {
        //启动
        SpringApplication.run(BootServer.class);
    }
}

Pay attention to the location of the startup class,

How to quickly build a springboot project

BootServer.java is under the parent package com.my.template, If it is not there, some annotations may not be useful. I will talk about it later. Remember to remember the location of the startup class BootServer. We can just run the main method of BootServer.

How to quickly build a springboot project##The above log appears, indicating that the service has been started and the port is 8080. Let’s access it,

How to quickly build a springboot projectThis is because the root path 127.0.0.1:8080 has no content returned. Let’s write a test Controller to practice.

package com.my.template.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class TestServer {
    @ResponseBody
    @RequestMapping("test")
    public String test(){
        return "hello springboot";
    }
}

Access the address 127.0.0.1:8080/test. The results are as follows,

How to quickly build a springboot project

# successfully returned "hello springboot", proving that our service is normal.

The above is the detailed content of How to quickly build a springboot project. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete