【问题标题】:Production mode not enabled in Jhipster ApplicationJhipster 应用程序中未启用生产模式
【发布时间】:2014-09-17 02:31:37
【问题描述】:

我正在使用 Jhipster 开发一个 Spring 应用程序。

当我需要部署时,我使用mvn -Pprod package。此命令生成 2 个 War 文件:xxx.warxxx.original.war。我在本地 Tomcat 中部署 xxx.original War 文件。

虽然我确信这是正确的过程,但应用程序的行为仍然与使用 DEV 配置文件时一样。

是否支持生产模式?

【问题讨论】:

    标签: java spring-boot jhipster


    【解决方案1】:

    Jhipster支持生产模式,就是上面详述的过程,根本不完整。

    原因

    -Pprod 参数用于配置生产模式的构建,但它不会告诉 Tomcat 实际启用该模式,因此它会回退到默认的“开发”模式。

    解决方案

    in Jhipster on-line documentation 所述,要启用生产模式,只需将-Dspring.profiles.active=prod 添加到您的JAVA_OPTS。例如,您可以通过编辑 <tomcat-home>/bin/setenv.sh / .bat 文件来实现此目的。

    【讨论】:

    • 如何检查 prod 模式是否已激活?
    • 首先请记住,spring.profiles.active 属性可以在整个应用程序中作为系统访问。然后只需使用它来有条件地加载css。此样式表可以设置特定的标题背景颜色或显示彩色丝带(位于页面左上角,红色背景,白色文本,金色上下边框,45 度旋转)。
    • 根据 jhipster 文档:Please note that this WAR file uses the profile we selected when building it. As it was built using the prod file in the previous section, it will therefore run with the prod profile. 还有:When you run your production application from a WAR file, the default is to use the same profile(s) as used during packaging. If you want to override this, you can explicitly provide an alternative in VM argument: ./java -jar jhipster-0.0.1-SNAPSHOT.war --spring.profiles.active=... 所以它应该使用 prod 配置文件而不是 dev 配置文件运行。
    【解决方案2】:

    您可以在 conf/catalina.properties 中添加以下内容

    spring.profiles.active=prod

    让 tomcat 选择 prod 配置文件。

    如果没有提供配置文件 - JHipster 选择默认配置文件 - 即 dev。

    你可以看看ApplicationWebXml.java,Application.java看看,dev profile是默认的。

    我们为避免任何问题所做的另一项更改是

    1. 将 prod 设置为 master 中的默认配置文件

    2. 将 dev 作为默认配置文件保留在开发分支中(发生主动开发的地方)

    【讨论】:

      【解决方案3】:

      使用此命令打包:

      ./mvnw -Pprod -Dspring.profiles.active=prod package
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-07-21
        • 2023-03-22
        • 2016-11-16
        • 1970-01-01
        • 2018-10-11
        • 2015-05-10
        • 2018-12-07
        相关资源
        最近更新 更多