spring boot gradle 学习笔记(1)

来源:互联网 发布:java 系统当前时间 编辑:程序博客网 时间:2024/06/08 16:04

1、编码环境:jdk版本1.8、intellij idea版本2016.2.5、gradle版本3.2

2、新建项目
项目的build.gralde配置如下:

group 'org.changs'version '1.0-SNAPSHOT'apply plugin: 'java'sourceCompatibility = 1.8repositories {    mavenCentral()    jcenter()}dependencies {    testCompile group: 'junit', name: 'junit', version: '4.11'    compile("org.springframework.boot:spring-boot-starter-web:1.4.3.RELEASE")    testCompile("org.springframework.boot:spring-boot-starter-test:1.4.3.RELEASE")}

3、添加Application入口函数

package org.changs.learn;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;@Configuration@EnableAutoConfiguration//自动扫描该包下的所有包、类@ComponentScan//自动扫描加载@Configuration注解的配置类public class Application {    public static void main(String[] args) {        SpringApplication.run(Application.class, args);    }}

4、添加示例接口:

package org.changs.learn.web;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/** * Created by yincs on 2017/1/9. */@RestControllerpublic class HelloController {    @RequestMapping("hello")    public String hello() {        return "hello spring-boot";    }}

5、运行Application类的main函数,启动成功后用浏览器访问http://localhost:8080/hello。页面上出现hello spring-boot!
ok!初步搭建已完成。

0 0
原创粉丝点击