-
Notifications
You must be signed in to change notification settings - Fork 337
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
Registering resources in ResourceConfig leads to warnings #3700
Comments
@jansupol Commented |
@unclejamal Commented |
@electrum Commented |
@jvissers Commented |
@Cousjava Commented |
|
The predicate that tells if a component class is "correctlyConfigured" only checked the 'resourceClasses' collection to determine whether the resource is actually a resource. As a consequence a warning, was logged when an instantiated resource class was tested: "WARNING: A provider war.HelloWorldResource registered in SERVER runtime does not implement any provider interfaces applicable in the SERVER runtime. Due to constraint configuration problems the provider war.HelloWorldResource will be ignored." The fix is as conservative as possible. Changed the result of the relevant predicate only in the context where the changed result values should not have any impact. But the side-effect of logging a warning should go away. No additional test since the change shouldn't have any observable effect other than the absence of a warning.
Can you pls test this commit and push it to master? The dropwizard project wants to have a fix, see dropwizard/dropwizard#2418, dropwizard/dropwizard#2395 |
The same is true about spring-boot. |
@Tibor17 We cannot merge unless the commit contains the sign-off, I am sorry. |
@jansupol how do we get a sign-off? |
@serhiypal |
@jansupol. Ah, thanks. Then what about this one: #3918. |
The behavior of Jersey in that case seems to be correct (described issue is not a bug) Jersey supports 2 ways of components registration - Class based registration and Instance based registration. When the class based registration is used the life-cycle of components is fully managed by the JAX-RS implementation or any underlying IoC container supported by the implementation. On the other hand when the instance based registration is used the life-cycle of providers registered using this instance-based register(...) is not managed by JAX-RS runtime. That is the reason why the HelloWorldResource instance is not recognized as a resource. It is expected to implement some Provider interface (which is noted in the WARNING). However it still works because the registration is valid even though it did not pass through JAX-RS IoC. But for resources which are not going to be providers nor features (not implement those interfaces) there is class based registration which shall be called like |
@Tibor17 it appears the WARNING is expected, so dropwizard should be adopted to slightly changed behavior |
Extract from Jersey API documentation (Configurable.class):
Closing the issue as not a bug, the framework works as designed. |
@senivam We use Jersey with spring-boot and we have the resources as Spring beans. Then we register the resources with Jersey using ResourceConfig.register(Object). It would not be possible for us to register them as a class because then Jersey would create a separate instance without the right dependencies. If the WARN points out the wrong way, what is the idiomatic way of registering resources managed by an external container? |
@bcalmac there is a PR #3820 which provides implementation for that. However it is not merged for now (because not all requirements are completed, after that it is going to be merged). So in short when you are required to register a resource by instance it would be preferable to do as
but because it is not merged yet (thus is not implemented) you can still use instance registration with warning but as soon as it is merged and released it would be preferable to modify your code accordingly |
I investigated some more the registration by class in a Spring Boot application and I'll leave my findings here for people that might be wondering how this works. Spring Boot does recommend registering the resources by class: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-jersey @Component
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
register(Endpoint.class);
}
} How does this work though? How would Jersey invoke the actual Spring bean at runtime? The answer is that Jersey doesn't instantiate the resource class. Instead, |
@bcalmac The above linked dropwizard PR (dropwizard/dropwizard#2463) does instance registration by registering an AbstractBinder implementation that binds the instance to its class. Not sure if that's truly idiomatic, but something similar could work for spring-boot. |
@bcalmac Since Jersey 2.26 and Spring Boot 2, Spring can manage the lifecycle of the endpoints. Although I'm not sure |
Hi,
we register Resources using the ResourceConfig.register(Object object) method. This works and has worked until now. However now (2.26) we are getting a warning:
Oct 17, 2017 1:47:00 PM org.glassfish.jersey.internal.inject.Providers checkProviderRuntime WARNING: A provider war.HelloWorldResource registered in SERVER runtime does not implement any provider interfaces applicable in the SERVER runtime. Due to constraint configuration problems the provider war.HelloWorldResource will be ignored.
It looks like the check assumes that no resources are registered in this way. Is this a bug or are we misusing the ResourceConfig API?
I've attached a minimal reproducing case based on the jersey-example-java8-webapp archetype. Running war.App leads to the warning above.
Thanks & best regards,
Silvestre
The text was updated successfully, but these errors were encountered: