Inject Spring beans into RestEasy

后端 未结 4 1065
迷失自我
迷失自我 2021-01-05 12:39

Is it possible to inject Spring beans into an RestEasy @Path class? I managed to do it with Jersey, with @InjectParam annotation, but for some other reasons, I need to switc

相关标签:
4条回答
  • 2021-01-05 12:44

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

    That way you can easily inject your Spring Services by @Autowired annotation in these classes.

    0 讨论(0)
  • 2021-01-05 12:51

    Simply annotate your RestEasy class with Spring's @Component and then inject your beans using Spring's @Autowired. Don't forget to include the annotation-config and component-scan elements in your spring configuration.

    0 讨论(0)
  • 2021-01-05 12:54

    There is a working example that integrates RestEasy with Spring just try spring-resteasy.

    0 讨论(0)
  • 2021-01-05 13:02

    You could use the @Configurable annotation to make a normal class (created by new) a spring Bean. Then you can use the normal Spring annotation to inject everything in that class/instance like in a "normal" Spring Bean.

    But that requires AspectJ!

    @See Spring Reference Chapter 7.8.1 Using AspectJ to dependency inject domain objects with Spring

    0 讨论(0)
提交回复
热议问题