spring-cloud-config: Properties not resolved on FactoryBean initialization

I’ve been using the Spring Cloud Config Client to connect to a config server on PCF. Unfortunately I’m using some legacy code that loads a keystore in an afterPropertiesSet of an InitializeBean, which is also a FactoryBean.

I noticed that when using the Config Client, the properties are not resolved even when they’re available in an application.properties. Strange thing is that one of the properties, location of type Resource is resolved.

My question is: Is this expected behavior and am I just missing something, or should all the properties be available when the bean is initialized? I’m guessing the latter so it seems like a bug to me and that’s why I’m submitting it here.

Here’s a link to a demo project illustrating the behavior: https://github.com/D0rmouse/spring-cloud-config-1167

You’ll see the following output when running the application:

Location: class path resource [somekeystore.jks]
Password: [$, {, s, s, l, ., k, e, y, s, t, o, r, e, ., p, a, s, s, w, o, r, d, }]
Type: ${ssl.keystore.type}

After removing the spring-cloud-starter-config dependency and running again the output will be:

Location: class path resource [somekeystore.jks]
Password: [c, h, a, n, g, e, i, t]
Type: jks

I would expect both outputs to be the same.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 35 (22 by maintainers)

Most upvoted comments

Wow that’s really easy. So you probably didn’t even run the app and see that the properties are loaded before the bean is instantiated. You don’t even believe me…

Again: You ‘fixed’ the problem by preventing the cascade, but what you should have done is made sure the Factory instantiating the FactoryBean is aware of the properties that have already been fetched…

@D0rmouse see https://github.com/spring-cloud/spring-cloud-commons/pull/436. You can try building and installing that branch and then using Finchley.BUIL-SNAPSHOT and seeing if it fixes the issue. It appears to work for me.