简体   繁体   English

Google App Engine 上 Spring Boot 应用程序的 Maven 配置文件

[英]Maven Profile for Spring Boot App on Google App Engine

I have a spring boot app that I d like to deploy on Google app engine using the app engine maven plugin.我有一个 Spring Boot 应用程序,我想使用应用程序引擎 maven 插件将其部署在 Google 应用程序引擎上。

Everything works fine except I cannot find a way that Google app engine loads the correct application.properties file for the spring boot app.一切正常,除了我找不到 Google 应用引擎为 Spring Boot 应用加载正确的 application.properties 文件的方法。

I have application-prod.properties, application-default.properties and application-test.properties.我有 application-prod.properties、application-default.properties 和 application-test.properties。 Locally I can easily choose which environment/profile to start using for example例如,在本地我可以轻松选择要开始使用的环境/配置文件

mvn appengine:run -Dspring.profiles.active=prod

But when I try to do the same for the deploy job, like但是当我尝试为部署工作做同样的事情时,比如

mvn appengine:deploy -Dspring.profiles.active=prod

That does not work.那行不通。 It does not load application-prod.properties but falls back to application-default.properties.它不会加载 application-prod.properties 而是回退到 application-default.properties。

Do I missunderstand something or should that work?我是否误解了某些东西,或者应该这样做吗? If that won't work since Google app engine just starts the war without passing in any param, is there a way to define environment variables for the app/service on Google where I can store stuff like database url and credentials that are environment specific?如果这不起作用,因为谷歌应用程序引擎只是在没有传递任何参数的情况下开始战争,有没有办法为谷歌上的应用程序/服务定义环境变量,我可以在其中存储诸如数据库url和特定于环境的凭据之类的东西?

Thanks for your help guys.谢谢你们的帮助。

If using App Engine flexible environment , in your app.yaml add the following如果使用App Engine 柔性环境,请在您的app.yaml添加以下内容

env_variables:
    JAVA_USER_OPTS: '-Dspring.profiles.active=prod'

This will be added to the JVM start command by the runtime.这将由运行时添加到 JVM 启动命令中。 See documentation for the openjdk-runtime.请参阅 openjdk 运行时的文档 By default, your app is using the jetty-runtime, which inherits the options from the openjdk-runtime.默认情况下,您的应用程序使用 jetty-runtime,它继承了 openjdk-runtime 的选项。

If using App Engine standard environment , in your appengine-web.xml add the following:如果使用App Engine 标准环境,请在您的appengine-web.xml添加以下内容:

<system-properties>
  <property name="spring.profiles.active" value="prod" />
</system-properties>

Try using the jvmFlags parameter for starting your application with the desired property, https://cloud.google.com/appengine/docs/standard/java/tools/maven#development_server_goals尝试使用jvmFlags参数启动具有所需属性的应用程序, https: jvmFlags

<jvmFlags>
  <jvmFlag>-Dspring.profiles.active=prod</jvmFlag>
</jvmFlags>

The current answers did not work for me.目前的答案对我不起作用。

Instead (because I am using app.yaml instead of app-engine.xml) I added the following two lines to my app.yaml:相反(因为我使用 app.yaml 而不是 app-engine.xml)我在 app.yaml 中添加了以下两行:

env_variables:
    SPRING_PROFILES_ACTIVE: "myProfileName"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM