将Spring bean注入RestEasy [英] Inject Spring beans into RestEasy
问题描述
是否可以将Spring bean注入RestEasy @Path类中?我设法通过Jersey和@InjectParam注释完成了此操作,但是由于其他一些原因,我需要切换到RestEasy,而且我似乎找不到解决方法(尝试了javax.inject.Inject,但没有).
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 switch to RestEasy, and I can't seem to find a way to do it (tried good ol' javax.inject.Inject, but nothing).
编辑
此解决方案有效: http://www.mkyong.com/webservices/jax-rs/resteasy-spring -integration-example/
但这不是注射..我仍然希望更优雅一些.
but it's not injection.. I'd still prefer something a little more elegant.
推荐答案
用Spring的@Component注释RestEasy类,然后使用Spring的@Autowired注入bean.不要忘记在您的spring配置中包括注解配置和组件扫描元素.
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.
这篇关于将Spring bean注入RestEasy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!