Inject Spring beans in RestEasy

Is it possible to insert Spring beans into the RestEasy @Path class? I managed to do this with a Jersey with the @InjectParam annotation, but for some other reasons I need to switch to RestEasy and I cannot find a way to do this (tried a good ol 'javax.inject.Inject, but nothing).

EDIT

This solution works: http://www.mkyong.com/webservices/jax-rs/resteasy-spring-integration-example/

but this is not an injection. I would prefer something a little more elegant.

+6
source share
4 answers

Just add your RestEasy class using Spring @Component and then enter beans using Spring @Autowired. Remember to include configuration annotation and component scan elements in your Spring configuration.

+3
source

There is a working example combining RestEasy with Spring, just try spring-resteasy .

+2
source

You can use the @Configurable annotation to create a normal class (created by new ) a spring Bean. Then you can use the standard spring annotation to insert everything into this class / instance, as in a "normal" spring Bean.

But that requires AspectJ!

@See Spring Link Chapter 7.8.1 Using AspectJ for Dependencies Embeds Domain Objects with Spring

0
source

I completely agree with Peter's answer, but there is another way to do this: you do all your beans presentation (RESTEasy or JAX-WS, which are not Spring components), extending SpringBeanAutowiringSupport .

That way, you can easily embed your Spring services on @Autowired annotations in these classes.

0
source

Source: https://habr.com/ru/post/906891/


All Articles