The construction of the traditional spring project framework requires a lot of configuration, and the development and testing of the project need to rely on the server, which makes the development relatively time-consuming. Spring boot solves the above problems very well. It sub-packages the cumbersome spring configuration, and generally speaking, the spring boot framework can be run without any configuration of spring. In addition, since spring boot comes with its own server, the project can be run directly in the form of jar, which facilitates the deployment of development and testing. The following is a brief introduction to the construction and operation of the spring boot framework.
1. Configure the sts plugin
Click on help on Eclipse-->Eclipse marketplace...-->Popular
Find the STS plugin
If install is displayed in the lower left corner, it means that STS is not installed, click install to complete the STS installation
2. Create a new Spring Start Project
File——>New ——>Other...
Find Spring Start Project under Spring Boot and click New Project
Click next, and modify the name, Group, Artifact, Version, Package and other information as appropriate
Click on next to add the required support. As an example, only web support is added here.
Click Finish, wait a moment to complete the project creation
3. Write test code
Create a new controller package in com.spring.springboot.mydemo under src/main/java, and create a new TestMyDemoController class
The code in the class is as follows:
package com.spring.springboot.mydemo.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/") public class TestMyDemoController { @RequestMapping("/hello") public String hello(String from) { return "hello "+from +" returned by server"; } }
Open the MydemoApplication class, right click -> run as -> spring boot app to start the project
访问http://localhost:8080/hello?from=client
Returning hello client returned by server indicates that the project is successfully built
4. Deployment
Right-click on the project -> run as -> maven install package and run to refresh the target, then the jar will appear under the target
Open the target folder, double-click mydemo-0.0.1-SNAPSHOT.jar to start the jar
访问http://localhost:8080/hello?from=client
return hello client returned by server
You can also cmd and press Enter to open the dos page, enter the full path where java -jar jar is located to start the project
访问http://localhost:8080/hello?from=client
return hello client returned by server