【问题标题】:Spring Boot Gradle plugin bootRun task not recognizing when static files are generated by Yeoman and updated with gruntSpring Boot Gradle 插件 bootRun 任务无法识别 Yeoman 何时生成静态文件并使用 grunt 更新
【发布时间】:2014-01-29 14:06:59
【问题描述】:

我有一个使用 Yeoman 生成的 Backbone 应用程序。使用 Spring Boot Gradle 插件和 bootRun 任务来运行应用程序,当我对我的 JS 源进行更改并运行 Grunt 以将我的源重新编译/缩小到 dist 目录时,这些更改不会反映在当前运行的 bootRun 任务中.

build.gradle

buildscript {
    repositories {
        maven { url "http://repo.spring.io/snapshot" }
        maven { url "http://repo.spring.io/milestone" }
        mavenLocal()
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:0.5.0.M7"
    }
}

apply plugin: "java"
apply plugin: "idea"
apply plugin: "spring-boot"
apply plugin: "war"

war {
    baseName = "mis-support-client"
    version =  "1.0.0-SNAPSHOT"
    includes = ["dist/**"]
}

repositories {
    mavenCentral()
    maven { url "http://repo.spring.io/libs-snapshot" }
}

dependencies {
    testCompile "junit:junit:4.11" 

    compile ("org.springframework.boot:spring-boot-starter-web:0.5.0.M7") {
        exclude module: "spring-boot-starter-tomcat"
    }
    compile "org.springframework.boot:spring-boot-starter-jetty:0.5.0.M7"
    compile "org.springframework.boot:spring-boot-starter-security:0.5.0.M7"
    compile "org.springframework.boot:spring-boot-starter-websocket:0.5.0.M7" 
    compile "javax.inject:javax.inject:1"
    compile "org.codehaus.jackson:jackson-mapper-asl:1.9.12"
    compile "org.apache.httpcomponents:httpclient:4.3.1"
    compile "commons-io:commons-io:2.4"
}

task wrapper (type: Wrapper) {
    gradleVersion = "1.8"
}

这是我用于映射“dist”目录的客户资源处理程序。

@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/bower_components/**", "/scripts/**", "/styles/**", "/fonts/**", "/font/**")
                .addResourceLocations("/dist/bower_components/", "/dist/scripts/", "/dist/styles/", "/dist/bower_components/bootstrap/fonts/", "/dist/bower_components/font-awesome/font/")
                .setCachePeriod(315569126);
    }

【问题讨论】:

  • 请附上你的 gradle.build
  • Gradle 和 Spring 对生成的资源或用于创建它们的过程一无所知。我相信您应该能够在src/main/resources/static(等)中编辑静态资源并在正在运行的应用程序中查看这些更改(也许您可以确认?)。
  • 我会试试看的。我对 Gradle 和 Boot 仍然很陌生,所以这只是弄清楚事情是如何工作的过程。在我尝试过您的建议后会发布反馈。
  • 好的。如果 grunt 在众所周知的位置生成资源,我们可能会为您检测更改(或允许您在 Gradle 中配置它)。如果您可以在 github(或类似网站)上分享一些东西,那么一个完整的、最小的示例项目将是一个有用的起点。
  • 我在 Bitbucket bitbucket.org/pgrimard/spring-boot-backbone/overview创建了一个仓库

标签: backbone.js gradle spring-boot


【解决方案1】:

我创建了一个 Yeoman 插件,它做同样的事情,但使用 Maven。

我们有一个使用 Maven 构建的 Spring Boot 后端,它与一个使用 Grunt 构建的 AngularJS 前端配合得很好。

你可以在这里找到这个 Yeoman 生成器:https://github.com/jhipster/generator-jhipster

【讨论】:

    【解决方案2】:

    我让您的应用程序运行,并验证从 src/main/resources 提供的资源可以重新加载,但直到今天,只有我使用 Maven(这里是 issue about that)。如果您想进一步讨论,github问题我很好。

    【讨论】:

      猜你喜欢
      • 2014-06-30
      • 2019-01-17
      • 2016-08-23
      • 2017-10-04
      • 1970-01-01
      • 2020-06-18
      • 1970-01-01
      • 1970-01-01
      • 2020-12-14
      相关资源
      最近更新 更多