“Could not find a suitable constructor” when extracted interface from my resource class with Jersey 2

人走茶凉 提交于 2019-12-07 03:34:04

问题


How can I make Jersey understand that it should use a concrete class instead of the interface for a resource?

I had a working app with a Status resource. Then I extracted an interface IStatus, and moved all JAX-RS annotations there. Now, I get:

org.glassfish.hk2.api.MultiException A MultiException has 1 exceptions.  They are:1. java.lang.NoSuchMethodException: Could not find a suitable constructor in resource.IStatus class

I know that this works with RestEasy. Is there any way of making it work with Jersey?


回答1:


Put the class level @Path on the implementation instead of the interface. Jersey is trying to instantiate the interface, which it can't.




回答2:


To whoever reach this thread and the above wasnt the issue, in my scenario it was this :

"Please pay special attention to constructors annotated with @Inject. It is a common mistake to import com.google.Inject instead of javax.inject.Inject. Currently"

from here : https://github.com/jersey/jersey/issues/2390

that solved the issue ! :)



来源:https://stackoverflow.com/questions/35362956/could-not-find-a-suitable-constructor-when-extracted-interface-from-my-resourc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!