基于gradle的springboot入门demo

1在安装jdk,gradle的前提下,主要是操作,至于原理去网上巴拉吧。

  • 创建工程名:demo,以及工程目录
mkdir demo
mkdir -p src/main/java
mkdir -p src/main/resources
mkdir -p src/test/java
mkdir -p src/test/resources
  • 在demo目录下创建build.gradle
 buildscript {
        repositories {
         mavenCentral()
            maven { url "http://repo.spring.io/snapshot" }
            maven { url "http://repo.spring.io/milestone" }
        }
        dependencies {        
             classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.0.BUILD-SNAPSHOT")
   }
  }
  
  apply plugin: 'java'       
  apply plugin: 'spring-boot'
 //apply plugin: 'war'      
  
 jar {                      
     //baseName = 'helloworld'
      //version =  '0.1.0'
  }
 
  repositories {
      mavenCentral()
      maven { url "http://repo.spring.io/snapshot" }
      maven { url "http://repo.spring.io/milestone" }
  }
 
 dependencies {
        compile("org.springframework.boot:spring-boot-starter-web")
        testCompile("junit:junit")      
 }
  • 在src/main/java/包名/Application
  1 package studio.codeocean;  
  2 import org.springframework.boot.*;
  3 import org.springframework.boot.autoconfigure.*;
  4 import org.springframework.stereotype.*;
  5 import org.springframework.web.bind.annotation.*;
  6 @SpringBootApplication
  7 @RestController
  8 public class Application {
  9 
 10     @RequestMapping("/hello")
 11     public String greeting() {
 12         return "Hello World!";
 13     }
 14     
 15     public static void main(String[] args) {
 16         SpringApplication.run(Application.class, args);
 17     }
 18 
 19 }
 20 

退到demo目录下gradle build,成功后在demo目录下输入java -jar /build/libs/demo.jar
在地址栏上敲入:http://localhost:8080/hello
显示Hello World! 说明踏上了springboot 的征程啦!

你可能感兴趣的:(基于gradle的springboot入门demo)