Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain VCAP_APPLICATION's application_name value on Spring's application.yml

I'm trying to set a logging pattern using 'logging.pattern.console' that needs to include the CloudFoundry's application name of a given application. I know that application names can be found as part of the VCAP_APPLICATION env variable with the 'application_name' key, and I can resolve env variables on Spring Cloud applications using the standard Spring placeholder notation, available on the application.yml file; but as the variable is a Json, I can't parse it nor use SpEL to obtain the requested value only.

Is there any other way to obtain the application name as set on the manifest.yml file in the application.yml?

like image 934
gnzlrm Avatar asked Dec 19 '22 09:12

gnzlrm


1 Answers

If you are using Spring Boot, you can access the application name with the property vcap.application.name. You should be able to reference this anywhere that properties are available, like @Value annotations or in application.properties.

Spring Boot's CloudFoundryVcapEnvironmentPostProcessor takes the VCAP_SERVICES & VCAP_APPLICATION environment variables and makes them available as properties through Spring's Environment api. This should happen automatically, no config or work necessary.

like image 157
Daniel Mikusa Avatar answered Dec 28 '22 06:12

Daniel Mikusa