A, Spring basic concepts Boot
Spring makes the emergence of JAVA EE development easier, but the configuration it was relatively trouble, you need to rely on good management of the project, decide that you need to use those libraries, and the libraries and version if you choose wrong, between each other but also create a conflict of It will be a considerable impact on our development.
Spring Boot emergence of a good solution to this problem.
Spring characteristics of Boot:
1 , the development of faster entry of all Spring
2 , out of the box, provide a default configuration, but through their own set parameters to get rid of in this way.
3 , provides a number of large projects in common non-functional features such as embedded servers, security, index, health monitoring, configuration and other externalization
4 , the code is not generated, no need to configure XML
We can use SpringBoot create java applications, java -jar start using it, or traditional war deployment.
Second, the rapid build Spring Boot
1 , Gradle preparations
Google is using to add Gradle dependency, Gradle dependency management personal feeling stronger than maven, easy to use scripting than Ant, so I chose this way. If you have installed Gradle, then you can skip this step.
2 , the project generated acquaintance:
Enter the URL: https://start.spring.io/
In the search for dependencies to add search web, select the web, and then click Create
Then generates a compressed zip, unzip, and copy storage path, for example:
C:\Users\Administrator\Downloads\demo
3 , the use of imported spring boot project gradle
File ==> open:
Build.gradleg original content
plugins { id 'org.springframework.boot' version '2.1.5.RELEASE' id 'java' } apply plugin: 'io.spring.dependency-management' group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '1.8' repositories { maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'} } dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' }
Click refresh, even if the project is to deploy better
4 , springboot project start
First, modify the directory structure, the demo package rename Controller, a new class TestController
Similar to the controller then moves the packet DemoApplication directory
DemoApplication is to start class, it is equivalent to the person in charge of project management, you threw him below the control level is certainly to be wrong
5 , TestController.java class
package com.example.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 这里的@RestController相当于 @ResponseBody+@Controller
* 使用@RestController相当于使每个方法都加上了 @ResponseBody 注解
* created by cfa 2018-11-06 下午 11:30
**/
@RestController
public class TestController {
/**
* 这里的@GetMapping相当于@RequestMapping(value = "/hello", method = RequestMethod.GET)
* created by cfa 2018-11-06 下午 11:29
**/
@GetMapping("hello")
publicString test(){
return "i love java";
}
}
Then run the project
Reproduced in: https: //www.jianshu.com/p/4697a1bfa750