Spring Boot everybody knows what Spring Boot is?

For your information, Spring Boot is awesome! .

By the way, stack length brings you the first Spring Boot application for young people, lifting code unprecedented ease, that is a word: cool!

The first step

Open this website and quickly generate a Spring Boot project.

start.spring.io/

No nonsense, look at the picture, a few seconds!

The second step

Unpack the generated demo project and import it into the IDE.

Take a look at the pom.xml file:

<? xml version="1.0" encoding="UTF-8"? > <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> < modelVersion > 4.0.0 < / modelVersion > < the parent > < groupId > org. Springframework. Boot < / groupId > The < artifactId > spring - the boot - starter - parent < / artifactId > < version > 2.1.5. RELEASE < / version > < relativePath / > <! -- lookup parent from repository --> </parent> <groupId>cn.javastack</groupId> <artifactId>demo</artifactId> < version > 0.0.1 - the SNAPSHOT < / version > < name > demo < / name > < description > demo projectforSpring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>
Copy the code

And the DemoApplication entry class:

@SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); }}Copy the code

Here is not too much introduction, I wrote this article in the Java technology stack wechat official account: “Spring Boot main class and directory structure introduction”, if not clear, can have a look.

The third step

Add the young person’s first Spring Boot request: /hello.

Modify DemoApplication to add a request method with the following code:

@RestController
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @GetMapping("/hello")
    public String hello() {
        return "hello"; }}Copy the code

The fourth step

Run the Spring Boot application and run the DemoApplication Main method in the IDE. Of course, there are many other ways to run Spring Boot, see: 3 Ways to run Spring Boot Applications! .

As shown in the picture, the program has started, awesome, started in 2 seconds, cool… It works because the Tomcat container is built in, but you can also replace or customize it, see Spring Boot Server Container Configuration.

Step 5

To access /hello request, visit the following link in your browser:

http://localhost:8080/hello

As shown in the figure below, the page outputs Hello.

conclusion

I created a demo project on the official website, imported it into the IDE, wrote a few lines of code and said hello, starting the first Spring Boot project for young people.

All I did was add five lines of code in a few minutes and no other messy XML configuration, which was awesome.

Spring Boot I have written a lot of tutorials, are the latest combat dry goods, follow wechat public account, in the background reply: “Boot”, you can get, the following is only part of the preview.

  • Several ways for Spring Boot to read configurations
  • How to verify Spring Boot parameters?
  • Spring Boot most core 25 notes!
  • Spring Boot 2.x startup process source code analysis
  • Spring Boot 2.x new features summary and migration guide

The stack manager will continue to push the latest progress and hot technology tutorials of Spring Boot on the official account as soon as possible. Finally, which version do you use? Welcome to leave a message