【问题标题】:Spring Boot Gradle setupSpring Boot Gradle 设置
【发布时间】:2016-10-08 12:12:52
【问题描述】:

我尝试在eclipse Luna 中设置gradle 以获得一个简单的spring boot 应用程序,但没有下载任何jar。谁能告诉我我缺少什么? 我在命令行中运行了gradle clean build,它编译成功: 这是我的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");

    }

}

【问题讨论】:

  • 你有eclipse的gradle插件吗?
  • @mh-dev 是的,我愿意。我按照本网站的步骤安装了它:pbaris.wordpress.com/2014/08/25/…
  • 你是如何将项目添加到eclipse中的?
  • 我刚刚创建了一个新的 Gradle 项目,创建了两个类并复制粘贴了代码。
  • 需要将gradle项目导入eclipse,不能只打开代码

标签: eclipse spring gradle spring-boot


【解决方案1】:

评论中的答案:

需要安装gradle插件,然后导入gradle项目。 (不要忘记点击“构建模型”按钮)

【讨论】:

    猜你喜欢
    • 2017-10-11
    • 2014-12-29
    • 2019-03-02
    • 2018-10-30
    • 2018-12-24
    • 2020-07-30
    • 2022-08-04
    • 2015-10-15
    • 2017-08-01
    相关资源
    最近更新 更多