Skip to content
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

ConfigurationClassParser does not work with scanner-provided ClassLoader [SPR-15245] #19810

Open
spring-issuemaster opened this issue Feb 10, 2017 · 2 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Feb 10, 2017

Adrian J George III opened SPR-15245 and commented

When using a ClassPathBeanDefinitionScanner with a different class loader than the attached context, ConfigurationClassParser.asSourcreClass abandons the provided classloader and uses the context's loader instead. This leads to the class not being found and a failure of the context to initialize.

This line


calls through to
public SourceClass asSourceClass(String className) throws IOException {

which uses the local class loader.

The problem can be reproduced here
https://github.com/adrianjgeorge/classloading-poc


Affects: 4.3.6

Issue Links:

  • #14977 ConfigurationClassParser needs to load annotations through source class loader
@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Feb 13, 2017

Juergen Hoeller commented

We have a rather fundamental assumption that the context-level ClassLoader can see all the classes of the context's bean definitions, at least to the degree that it needs to introspect them and to generate proxy classes for them. This does not just apply to ConfigurationClassParser but to DefaultListableBeanFactory and GenericApplicationContext in general.

Even if we revised the factory to generally preserve the ClassLoader that a particular scanner uses for each scanned bean definition, you might still run into failures when creating proxies later on. There are several spots in the framework where we're making such general assumptions about the context-level ClassLoader.

Could you possibly configure your ApplicationContext with a synthetic ClassLoader which is actually able to see all affected classes?

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Feb 15, 2017

Adrian J George III commented

In this case the ClassLoader is sitting in front of an ear and providing dependency seperation, so i could get everything into one ClassLoader but that would defeat my purpose by allowing dependency bleedthrough and potentially causing failures.

Maybe it will help if I explain my use case.
You have three beans A, B, and C. B needs to be injected with A. C needs to be injected with A and B. A is the only one known at compile time, and the only one baked into my artifact. B and C are each in their own ear with their (potentially clashing) dependencies which are discovered at runtime. I need them all to live happily together in the same context, because I can't tell what order if any they could be built hierarchically since i don't control the artifacts with B and C.

Did that make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.