Jersey Inject Weld managed bean into ConstraintValidator

二次信任 提交于 2019-12-05 21:33:12

I also faced this issue with Jersey 2.25.x, Weld 2.4.x and Tomcat 8.x and haven't found a proper solution with @Inject.

As a workaround, I programmatically looked up for the bean instance using:

SomeSortOfBean bean = CDI.current().select(SomeSortOfBean.class).get();

Do you have the possibility to change the underlying JAX-RS implementation for your project?

When I had the same problem, I just switched from Jersey to RestEasy (fully certified JAX-RS implementation). http://resteasy.jboss.org/

Changing the implementation was easy enough: Just include the dependy through your favorite build automation tool (I use gradle):

compile 'org.jboss.resteasy:resteasy-servlet-initializer:3.0.11.Final'

Additionally, to make CDI work, include the resteasy-cdi JAX-RS CDI bridge:

compile 'org.jboss.resteasy:resteasy-cdi:3.0.11.

Lastly if you want the same JSON format, include the resteasy-jackson-provider:

compile 'org.jboss.resteasy:resteasy-jackson-provider:3.0.11.Final'

In the end, switching to resteasy gave me a lot less headache than trying to implement a Jersey fix.

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