【问题标题】:Spring bootRun not available from within Eclipse gradleSpring bootRun 在 Eclipse gradle 中不可用
【发布时间】:2017-05-27 23:04:15
【问题描述】:

我刚刚开始使用 Spring,并且已经成功设置并正在使用 Eclipse 中的 gradle buildship 运行 RESTful 教程。

https://spring.io/guides/gs/rest-service/#initial

但是,我无法在 Eclipse 中工作的一件事是它说您可以通过命令从 gradle 而不是 jar 直接运行应用程序:

gradle bootRun

但 bootRun 不是 gradle 脚本创建的任务,只是“运行”(不起作用)。所有其他条目,如“构建”等。

这没什么大不了的,因为我可以从命令行运行 jar,但我想从 Eclipse 中运行它(我也没有安装 gradle,只是 buildship)。

谢谢。

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

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

jar {
    baseName = 'gs-rest-service'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

【问题讨论】:

    标签: spring gradle buildship


    【解决方案1】:

    你不需要'gradle bootRun'

    只需将其作为主要方法运行:

    @SpringBootApplication
    public class DemoApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(DemoApplication.class, args);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-02-06
      • 2018-01-08
      • 1970-01-01
      • 2020-09-24
      • 2019-10-04
      • 2018-12-02
      • 1970-01-01
      • 1970-01-01
      • 2019-04-24
      相关资源
      最近更新 更多