Spring Boot Gradle设置

时间:2016-10-08 12:12:52

标签: eclipse spring gradle spring-boot

我尝试在gradle中为简单的eclipse Luna应用设置spring boot,但没有下载任何广告。谁能让我知道我错过了什么? 我在命令行中运行gradle clean build并成功编译: gradle clean build in workspace folder 这是我的build.gradle文件的内容:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'

jar {
    baseName = 'sample'
    version =  '0.1.0'
}
repositories {
    mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
}

这是带控制器的类的内容:

package sample;

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

@RestController
public class SampleController {

    @RequestMapping("/sample")
    public String sampleIt(){
        return "Hello! Welcome to Spring Boot Sample. ";
    }
}

这是具有主要功能的类:

package sample;

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

@SpringBootApplication
public class SampleApplication {

    public static void main(String[] args) {
        ApplicationContext ctx = SpringApplication.run(SampleApplication.class, args);
        System.out.println(ctx.getDisplayName());

        System.out.println("This is my first Spring Boot Example");

    }

}

1 个答案:

答案 0 :(得分:0)

评论中的回答:

有必要安装gradle插件并随后导入gradle项目。 (不要忘记单击“构建模型”按钮)