Gradle——构建springboot

框架下载http://download.csdn.net/download/qq_29423883/10045523
基本结构
这里写图片描述
装好Intellij IDEA之后,Gradle也就默认装好了,现在我们仅需直接创建工程:
选择Java了,Next:
这里写图片描述

GroupId,ArtifactId和Version,咋看起来和Maven一样?其实就是一样,后面我们还继续使用Maven的仓库呢。Next:

这里写图片描述

Use auto-import和Create directories for empty content roots automatically这两个选项勾上,Next:
填入项目名称,位置,OK,Finish。我们来看看项目的目录结构:
这里写图片描述
.gradle,gradle的相关支持文件,不用管
.idea,IntelliJ IDEA的相关文件,不用管
build,构建生成物,存放项目构建中生成的class和jar包
gradle,一个gradle的包装程序,貌似直接用gradle不太好,得再包一层,这个其实我们也不用管
src,我们写代码的地方,不用说了吧
build.gradle,gradle的构建配置,这是我们要关心的,相当于Maven的pom.xml
GradleLearn.iml,IntelliJ IDEA的项目文件
gradlew,一段gradle wrapper的运行脚本,For *nix
gradlew.bat,一段gradle wrapper的运行脚本,For Windows

需求:使用gradle构建springboot
1.新建一个gradle工程,选择java和webApplication
2.修改build.gradle文件如下

//应用插件
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'org.unbroken-dome.test-sets'
apply plugin: 'war'
//jdk版本
sourceCompatibility = 1.8
targetCompatibility = 1.8
//构建脚本
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath(
                'org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE',
                'org.unbroken-dome.gradle-plugins:gradle-testsets-plugin:1.0.2'
        )
    }
}
//使用maven仓库
repositories {
    mavenCentral()
}
//具体依赖
dependencies {
    compile(
            'org.springframework.boot:spring-boot-devtools',
            'org.springframework.boot:spring-boot-starter-actuator',
            'org.springframework.boot:spring-boot-starter-web'
    )
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

3.创建包什么的,结构如下
这里写图片描述

4springboot启动类

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @SpringBootApplication 注解可以让SpringBoot为我们按照默认约定进行所有的应用初始化配置,
 * 本类是在项目中唯一一个包含main方法的类,通常我们将该类创建在项目包的根目录下,
 * 在测试过程中,我们可以通过运行此类来运行SpringBoot应用
 */
@SpringBootApplication
public class SpringBootMain {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootMain.class, args);
    }
}

HelloController类

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
 *
 *测试Controller
 *@RestController 实现Rest服务的常用注解,相当于在@Controller的基础上,自动为将所有的请求方法追加@ResponseBody
 *实现以
 */
@RestController
@RequestMapping("/hello")
public class HelloController {

    /**
     * 该请求默认以rest方式返回hello word
     * @return
     */
    @RequestMapping(value = "/word",method = RequestMethod.GET)
    public String testHello() {
        return "helloWord";
    }

}

5.测试
在浏览器输入地址,返回helloword
这里写图片描述

参考:http://www.cnblogs.com/guogangj/p/5465740.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值