Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Everything works fine except I cannot find a way that Google app engine loads the correct application.properties file for the spring boot app.

I have application-prod.properties, application-default.properties and 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.

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?

Thanks for your help guys.

like image 364
mooonli Avatar asked Jun 28 '18 11:06

mooonli


People also ask

How do I deploy spring boot Microservices in GCP?

Configure Google Cloud Platform Console and SDK. Use Cloud SQL to create a MySQL instance. Configure the application for Spring Cloud GCP. Deploy the application to App Engine and test it.


1 Answers

If using App Engine flexible environment, in your app.yaml add the following

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

This will be added to the JVM start command by the runtime. See documentation for the openjdk-runtime. By default, your app is using the jetty-runtime, which inherits the options from the openjdk-runtime.

If using App Engine standard environment, in your appengine-web.xml add the following:

<system-properties>
  <property name="spring.profiles.active" value="prod" />
</system-properties>
like image 196
Mike E. Avatar answered Sep 23 '22 23:09

Mike E.