【问题标题】:spring bootRun and Angular buildWatch using Gradlespring bootRun 和 Angular buildWatch 使用 Gradle
【发布时间】:2018-01-08 23:12:25
【问题描述】:

我想在 Spring Boot 多模块应用程序中使用 Angular 4 作为客户端框架。 我的应用程序包含 3 个模块

  1. 域模块
  2. 服务模块
  3. web 模块(一个 Spring Boot 模块)

angular 4 根目录位于 web 模块中。

我可以启动 bootRun 以使用“ng build”命令执行应用程序(编译 angular typescript 文件并将结果文件复制到 springBoot 静态资源目录中) 这是你的工作(顺便感谢 Umesh Morsu 的出色教程https://www.youtube.com/watch?v=nHRA7cbL0vk)。

下面是我用来执行此操作的 gradle 脚本:

task buildClientDev(type: NpmTask, dependsOn: 'npmInstall') {
            group = 'build'
            description = 'Compile client side folder for development'
            args = ['run','buildDev']
        }


task buildClientWatch(type: NpmTask, dependsOn: 'npmInstall'){
            group = 'application'
            description = "Build and watches the client side assets for rebuilding"
            args = ['run','buildWatch']
}

bootRun{
    doFirst {
        tasks.buildClientDev.execute()
    }
}

这样做的问题是,当我修改 TypeScript 文件(生成 js 文件)时,我必须重新运行 bootRun。我希望这一代自动完成。所以我想打电话给tasks.buildClientWatch.execute(),它执行“ng build watch=true”。但是当我这样做时,springBoot 应用程序无法启动。 当我使用 doLast 而不是 doFirst 时,我的 Springboot 应用启动良好,但 doLast 中的 gradle 调用均未执行。

那么如何同时运行springBoot bootRun命令和ng build watch=true呢?

【问题讨论】:

  • “springBoot 应用程序无法启动” - 这是为什么呢?

标签: angular spring-boot gradle build watch


【解决方案1】:

在使用 Angular 开发应用程序 3 年后,我认为在这种情况下最好的办法是将前端与后端完全分离。

所以我可以为我的 Angular 前端应用程序创建一个 npm 或 gradle 项目。 对于后端,我可以根据需要创建微服务和模块。 我认为这是当今最好的模式。

【讨论】:

    【解决方案2】:

    我建议不使用 Gradle 直接使用 npm(因为我这样做没有任何问题)。大多数 IDE 也以组合构建/启动组的方式支持这一点。

    【讨论】:

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