*Note : This article is dedicated to recording the learning process and sharing learning experience!
I just started to understand the SpringBoot framework. I thought it was very useful and felt it was necessary to learn the framework in depth. Now I will create a SpringBoot project:
1. Create a new Project on IDEA and select Spring Initializr.
Project SDK Select the installed JDK;
Choose Initializr Service URL Select default (Default: https://start.spring.io)
Select a project template
Click Next
2. Configure project
Set the project array (group), project identity (artifact), Type selects a Maven Project to indicate that it is a maven project
Version: Project version number
Name: Project name
Description: Project description
Package: Project package name
Project configuration
Click Next
3. Select a project template
Let's choose to create a web project
Select Spring Boot Version
Select a project template
4. Set the project name and project path
Set project name and project path
After setting the project path and project name, click FInish to create the project and complete the project. You need to build the project and wait for a while to complete it.
5. The creation is completed, we delete the .mvn folder, mvnw file and mvnw.cmd file
Delete files
6. Let's take a look at the pom.xml file configured by maven, which contains the version library required for SpringBoot project operation.
pom.xml
The required libraries for SpringBoot to run are:
<!-- Basic library files for SpringBoot projects --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
<!-- Basic library files for SpringBoot projects --> <dependencies><!-- web project library --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency><!-- Test required library --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
7. Create a HelloService
package com.example.springbootdemo.service;import org.springframework.stereotype.Service;@Servicepublic interface HelloService { String saysHello();}8. Create HelloService implementation class HelloServiceImpl, implement the sayHello() method, and return "Hello World!"
package com.example.springbootdemo.service.impl;import com.example.springbootdemo.service.HelloService;import org.springframework.stereotype.Component;@Componentpublic class HelloServiceImpl implements HelloService { @Override public String saysHello() { return "Hello World!"; }}9. Create HelloController, call HelloService implementation class, and print "Hello World!" to the browser
package com.example.springbootdemo.service.impl;import com.example.springbootdemo.service.HelloService;import org.springframework.stereotype.Component;@Componentpublic class HelloServiceImpl implements HelloService { @Override public String saysHello() { return "Hello World!"; }}10. When witnessing the miracle, let’s run the project we built to see if it can be the same as we expected. Enter the access address in the browser http://localhost:8080/hello
You can see Hello World!
At this point, learning to create a SpringBoot project is completed.
View source code
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.