Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default spring profil ("cloud") in cloud foundry

I want to launch my spring-boot application after a cf push with a custom profile named my_profile, but the app is always launched with the default one cloud profile. How can I specify the exact profile to load?

I already tried to add the environment variable in the manifest.yml like this:

env:
      SPRING_PROFILES_ACTIVE: my_profile 

But the application was load with both profiles (cloud & my_profile)

Do you have a solution to load juste my custom profile and not integrate the default one?

like image 465
marherbi Avatar asked Jun 24 '19 13:06

marherbi


People also ask

How do I deploy a spring application to Cloud Foundry?

The API endpoint is the URL of the Cloud Controller in your Cloud Foundry instance. Note: You must use the cf CLI to deploy apps. From the root directory of your application, run cf push APP-NAME -p PATH-TO-FILE.jar to deploy your application. Note: Most Spring apps include an artifact, such as a .jar, .war, or .zip file.

How to enable cloud profile in Spring Boot?

The simplest choice is to set an env var JBP_CONFIG_SPRING_AUTO_RECONFIGURATION=' { enabled: false }', and use spring.datasource.* properties (e.g. in application.properties or a profile-specific version of that) to set the additional properties at runtime. The “cloud” profile is automatically activated for you by the buildpack. E.g.

What is the difference between Cloud Foundry and Spring Boot DataSource?

Locally Spring Boot will create a DataSource with an H2 embedded database. In Cloud Foundry it will bind to a singleton service of type DataSource and switch off the autconfigured one from Spring Boot.

How do I run CF login on Cloud Foundry API?

Run cf login -a API-ENDPOINT, enter your login credentials, and select a space and org. The API endpoint is the URL of the Cloud Controller in your Cloud Foundry instance. Note: You must use the cf CLI to deploy apps.


1 Answers

This is coming from the Java buildpack and it's Spring Auto-reconifguration support.

The Spring Auto-reconfiguration Framework adds the cloud profile to any existing Spring profiles such as those defined in the SPRING_PROFILES_ACTIVE environment variable.

https://github.com/cloudfoundry/java-buildpack/blob/master/docs/framework-spring_auto_reconfiguration.md

To disable this behavior, you can disable the Spring Auto-reconfiguration support.

Set an env variable JBP_CONFIG_SPRING_AUTO_RECONFIGURATION to { enabled: false }.

Ex:

cf set-env my-cool-app JBP_CONFIG_SPRING_AUTO_RECONFIGURATION '{ enabled: false }'

Please note that this will also disable the cloud.* properties and automatic rewriting of bean to configure services.

https://github.com/cloudfoundry/java-buildpack-auto-reconfiguration#what-is-auto-reconfiguration

like image 117
Daniel Mikusa Avatar answered Sep 24 '22 14:09

Daniel Mikusa