您的位置:首页 > 编程语言 > Java开发

gradle+springBoot入门示例

2017-03-02 14:57 831 查看
1.首先现在gradle 版本为2.2.1文件下载地址:http://gradle.org/gradle-download/

2.在intelliJ IDEA 14.0.2创建gradle项目

(1).File->New Product->Gradle如图所示:



(2).给工程命名为example



(3)创建完成后工程的目录结构为:



(4)在build.gradle中配置如下

[plain] view
plain copy

apply plugin: 'java'  

  

sourceCompatibility = 1.8  

version = '1.0'  

  

buildscript {  

    repositories {  

        jcenter()  

        mavenCentral()  

    }  

    dependencies {  

        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")  

    }  

}  

  

apply plugin: 'java'  

apply plugin: 'spring-boot'  

  

jar {  

    baseName = 'myproject'  

    version =  '0.0.1-SNAPSHOT'  

}  

  

repositories {  

    jcenter()  

    mavenCentral()  

}  

  

dependencies {  

    compile("org.springframework.boot:spring-boot-starter-web")  

    testCompile("org.springframework.boot:spring-boot-starter-test")  

}  

然后build项目



显示出gradle的界面,然后点击



然后程序会下载相应的jar包

3.创建个测试类



测试类中的源码:

[java] view
plain copy

import org.springframework.boot.SpringApplication;  

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;  

import org.springframework.web.bind.annotation.RequestMapping;  

import org.springframework.web.bind.annotation.RestController;  

  

/** 

 * Created by txw on 2015/12/29. 

 */  

@RestController  

@EnableAutoConfiguration  

public class Example {  

  

    @RequestMapping("/")  

    String home() {  

        return "Hello World!";  

    }  

  

    public static void main(String[] args) throws Exception {  

        SpringApplication.run(Example.class, args);  

    }  

  

}  

[java] view
plain copy

然后右击点击红色部分运行程序  

[java] view
plain copy

<img src="https://img-blog.csdn.net/20160103172244548?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />  

最后在浏览器中输入localhost:8080,出现如下结果表示成功!



转载出处:http://blog.csdn.net/txw910/article/details/50430178
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: