【问题标题】:Angular 2 profiles and tomcatAngular 2 配置文件和 tomcat
【发布时间】:2017-11-10 03:51:57
【问题描述】:

目前我正在运行一个后端 springboot 应用程序和一个前端 Angular2 应用程序。

我们不想在本地/开发/验收环境之间切换时更改代码,我们只想让我们的tomcat知道我们要使用哪个版本的部署。

对于我的后端,我能够遵循本指南 https://www.javacodegeeks.com/2012/06/spring-31-profiles-and-tomcat.html

现在我也想为我的前端 Angular2 应用程序执行此操作,但我真的不知道如何开始或在哪里查看。

谢谢

【问题讨论】:

  • 你在使用 angular-cli 吗?如果是这样,您可以在 .angular-cli.json 中声明环境并使用“ng build --environment=production”等构建不同版本的应用程序。当然,这只适用于编译时。如果您想在构建后更改环境,也许您可​​以为多个环境构建 angular 应用程序,并让 servlet 根据 spring 配置文件提供不同的 angular 构建。
  • 是的,我目前正在使用 angular-cli 并声明我的环境。但现在我想遵循“一次构建,随处部署”的原则,但这似乎比使用 Angular2 更困难。

标签: angular tomcat spring-boot profiles


【解决方案1】:

这可能不是最好的答案,但一种方法可能是:

1) 在您的 package.json 中定义不同的构建目标(为简洁起见,我省略了除 output-path 之外的所有选项),它们将使用不同的目录进行输出:

"scripts": {
    "build-prod": "ng build --output-path dist-prod",
    "build-dev": "ng build --output-path dist-dev"
 }

2) 在构建 Servlet 时,让 Maven(或您喜欢的其他构建工具)构建所有 Angular 变体。确保所有变体都将与您的 servlet 一起部署。

3) 为您的不同环境添加配置,这些配置将为正确的路径添加 ResourceHandlers,具体取决于该环境。我还没有使用过 Springboot,所以这里有一个来自常规 Spring MVC Java Config 的片段:

@Configuration
@Profile("dev")
public class DevConfig {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("/**").addResourceLocations("/dist-dev/")
                .resourceChain(true).addResolver(new PathResourceResolver());
    }

}

希望这会有所帮助,直到有人有更好的主意。 :-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-23
    • 2017-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多