0

I'm trying to use a custom-spring-boot-starter with a Configuration dependent on the presence of properties as a dependecy in my spring-boot-project. The starter's configuration is something like this:

@Configuration
@ConditionalOnProperty( {"vcap.services.my-user-provided-service.credentials.git.password"})
public class MyConfig {    
    @Bean
    public MyBean createBean() {
        [...]
    }    
}

everything works fine in the local environment when I pass the property "vcap.services.my-user-provided-service.credentials.git.password" to the startup command. However when I deploy the whole thing to cloudfoundry it doesn't create MyBean and subsequently the startup fails because an @Autowire on the Bean is failing. The log says that MyBean was not created because the property vcap.services.my-user-provided-service.credentials.git.passwordis missing.

I defined the variable in a cloudfoundry user provided service my-user-provided-service and bound it to the app and in the webconsole of cloudfoundry it appears in the env settings of the app as expected. When I add the variables directly to the app (e.g. via the manifest) it works, however I don't want to thave the credentials there.

It seems like the user provided service's variables are not (yet?) available in the properties during the context startup and therefore not found. Are they picked up after other property sources? Do I maybe have to use a @AutoConfigureAfter with some Bean of spring-cloud? I tried it with @AutoConfigureAfter(CloudFoundryVcapEnvironmentPostProcessor.class) but that didnt help.

Any help is greatly appreciated.

Korgen
  • 5,191
  • 1
  • 29
  • 43
  • If you haven't done this already, you should add Spring Boot Actuators to your app, deploy it to CF, then hit the `/env` (Boot 1.5) or `/actuator/env` (Boot 2) endpoint to inspect the environment. There should be a `vcap` block in the JSON response from that endpoint, which you can inspect to make sure that it includes the property you expect. – Scott Frederick Apr 13 '18 at 15:52
  • I did a quick test app and this seemed to work OK for me. Aside from using Actuators' `/env` and `/beans` endpoints to investigate, I'd suggest faking VCAP_SERVICES locally. You can simply `export VCAP_SERVICES=` on your local machine to test. There's nothing special that CF is doing, it's just setting an env variable with some JSON data. If you copy VCAP_SERVICES from your app on CF, you can export that as a local environment variable and your app should perform the same parsing and expose the same list of `vcap.services.*` properties. – Daniel Mikusa Apr 15 '18 at 19:01
  • @DanielMikusa as described locally it works without any problems when I set the variables. Will try to investigate the /env endpoint. However as I see the variables assigned in the pivotal apps console, I'd expect them to be available in the env endpoint too – Korgen Apr 16 '18 at 06:30

0 Answers0