-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properties not resolved on FactoryBean initialization #1167
Comments
I'm frankly a little confused about where |
@spencergibb @dsyer any thoughts? |
I’d say it’s expected. Decryption has to be applied to |
Wait. That comment only applies to regular cloud context behaviour. This is a custom bean that defines a key store. I’m not sure it’s even anything to do with spring cloud. |
It’s in the XML (the bean definition). And it looks like it contains those placeholders. |
@dsyer Now I feel like a dummy. My IDE was being smart and automatically put the correct values in the editor instead of showing me the real values. So I never saw the properties in the XML file. At least that makes more sense now :)
Without Spring Cloud Config on the classpath it works as expected. It seems to have something to do with implementing |
I see. It's this code in if (this.environment == null && registry instanceof BeanFactory) {
this.environment = ((BeanFactory) registry)
.getBean(Environment.class);
} That looks like a really bad thing to do because Of course it's not an issue in |
Thanks so far. Setting the EDIT: This seems to only work for properties that are loaded from a local property source. Properties loaded from a Config Server will still not be resolved after disabling the refresh auto config. |
This only is a problem in Finchley, Edgware releases work fine. |
Disabling the I tried spring boot 1.5 with Edgware and it also failed to resolve properties retrieved from a Config Server for I'll see if I can update the application this weekend to demonstrate the behavior. EDIT: Added a Config Server to the demo project for easy testing. It's seems that disabling the refresh auto config does allow for correct remote property resolving, so I have to check my production setup to find out what could be causing them not to be resolved there... |
@D0rmouse see spring-cloud/spring-cloud-commons#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. |
I'm using I'm from Europe, so it will be tomorrow before I'll test it. Will let you know asap. |
You will have to switch to the spring cloud jars and not scs. |
I can confirm the fix works on the demo project with the Spring Cloud as well as the io.pivotal dependencies. When I deploy to PCF with the fix and use a PCF Config Server the properties are still not resolved when the FactoryBean is initialized. Maybe I go for connecting to the Config Server manually using only Spring Cloud dependencies and see what happens. EDIT: Below the warning message from the PCF app log:
|
I cant say for sure what it happening on PCF. In either case that is something you will need to talk to the SCS team about. Thanks for testing the fix! |
Fixed via spring-cloud/spring-cloud-commons#436 |
There's something about this issue that keeps bugging me... I now think the fix is done in the wrong place, and here's why: When you start the demo project with the config server (without @ryanjbaxter's fix), you can clearly see in the log that the properties are loaded before the So I think the real issue here is that these properties are not available to the context loading the
Now, all properties are available to the |
I couldn't reproduce your issue with remote configuration and a |
When you take the sample application, start
before
(of course, make sure @ryanjbaxter's fixed spring-cloud-context isn't on the classpath when running) So the properties are loaded, but not available to This clearly illustrates the properties could be available to I get that this may not be the place to address this issue, but what would be then? spring-framework? Or should the advice be just to not use property driven |
If you don’t have Ryan’s bugfix how will we know this is a new issue? In any case we should move the discussion to spring-cloud-commons because that’s where all the features are implemented. |
I have a feeling you haven't read what I posted, please re-read my previous two posts. I'm not talking about a new issue, but rather a different solution to this one. I'm saying that Ryan's fix does fix the bug, you can read I've tested it myself, but probably it could be fixed more genericly. Now you've prevented an instantiation cascade, while it would be better to provide the properties to the |
I certainly did read everything you wrote, but now I'm just confused. You seem to be saying that even with the newest snapshots you are seeing a problem that I can't reproduce. Please open an issue in spring-cloud-commons so we can continue the analysis. |
No not with the newest snapshots... I'm talking about the unfixed situation and how the log output in that situation shows that it could be fixed in a different, more generic way, |
I'm not sure I follow then (and nothing in the logs jumps out at me as wrong). We definitely needed to fix that cascade anyway, so what's wrong with the solution we have? |
The logs (from the unfixed output) show me that properties are available before the The cascade fix is ok for this scenario, but it doesn't fix the root issue, which is what I stated above. It should work even with the cascade, because the properties should already be available. So chronologically the properties are fetched from the Config Server and the cascade is triggered, but the properties are not available to the |
You are welcome to open an issue for that problem in spring cloud commons, but since it works now with the code the way it is (which is a fix we want regardless of what you are saying is true or not), it will be a low priority for us. |
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... |
Sorry we are very busy with many projects to maintain, we dont have time to run every single app and test every single thing. I did not say I didnt believe you, I was just instructing you what the correct course of action is to move forward. |
FWIW I ran it. I didn't see a problem. Seems like it's not really an issue to me. If you think it is then spring-cloud-commons is the place to discuss it. |
I understand you're busy and appreciate the instruction and I'll take it up with the commons people. I don't understand how it is you think that loading FactoryBeans without resolved properties while they clearly can be is not really an issue. Any cascade triggered from anywhere too early will become an issue until this is addressed, as I've already encountered. |
Same folks, code just lives in Commons |
Hi, I've tested with the following versions. The issue is not resolved.
I read Greenwich.M3 should contain spring-cloud-commons 2.1.0.M2, in which the issue should be resolved right? I also the FactoryBean issue has become more of an issue in this release than it was before in my production project. |
But as we said above this is not the repo this issue, please open an issue in spring cloud commons. |
Yes, but the demo project and the initial issue was submitted and solved here and this fix doesn't seem to work. This fix should at least fix the scenario in the demo project. It doesn't address the real issue, which is already created in spring-cloud-commons. |
Then that is the issue to track |
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 anInitializeBean
, which is also aFactoryBean
.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 typeResource
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:
After removing the
spring-cloud-starter-config
dependency and running again the output will be:I would expect both outputs to be the same.
The text was updated successfully, but these errors were encountered: