Open radarsh opened 6 years ago
Yes, please, provide a PR. Thank you.
PR #4080 provided. Contribution guidelines could be improved to link to the project's wiki for developer resources such as CI, signing off commits and a lot more. I had to trawl through existing pull requests to find the required information.
SpringComponentProvider
does not seem to honour application context hierarchies. Say we have a parent context with common filters and other Jersey components defined and then we have a child context where we have everything in the parent context made available (viaApplicationContext.getParent
) plus some additional components.When we try to start such an application (I'm using Spring Boot), we get the below errors:
The definition of
MyFilter
is a rather straightforward one:The same filter works absolutely fine when loaded from the parent context. It's as though the child context doesn't seem to be able to see that this bean has already been defined in the parent context and therefore the Spring-HK2 bridge gives up and tries to do DI using HK2 instead of Spring.
Upon further investigation the root cause seems to be the below block of code in
SpringComponentProvider
.The problem lies in the line
String[] beanNames = ctx.getBeanNamesForType(component);
.ApplicationContext.getBeanNamesForType
clearly states that it doesn't trace back the hierarchy:So in this case,
SpringComponentProvider
just expects to findMyFilter
to be registered in the child context which obviously it isn't and just falls back to HK2 which isn't aware of the constructor injection already set up in Spring.Let me know if you're accepting PRs and I'd be happy to submit one with the below change: