spring-boot and to build gradle

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

15063669-82d940d457cf26a6.png
image.png

Then generates a compressed zip, unzip, and copy storage path, for example:

C:\Users\Administrator\Downloads\demo

15063669-726b04b74fd22f35.png
image.png

3 , the use of imported spring boot project gradle

File ==> open:

15063669-fa343bee783abd42.png
image.png
15063669-f3a9c29350ce02cf.png
image.png
15063669-0a1e5ec767100836.png
image.png

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

15063669-f29b572e6b84b2fa.png
image.png

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

15063669-7296bc27e22ac30c.png
image.png

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


15063669-4e41d85ccc97e753.png
image.png

Reproduced in: https: //www.jianshu.com/p/4697a1bfa750

Guess you like

Origin blog.csdn.net/weixin_34061482/article/details/91059038