Pascal是正确的,您不能将d簧管理的东西注入焊豆(反之亦然)。
但是您可以定义一个生产者,该生产者获取春豆并将其提供给Weld。听起来,这是一个极端的技巧,而且我认为您不应该在一个项目中同时使用两个框架。选择一个,然后删除另一个。否则,您将遇到多个问题。
这是它的样子。
@Qualifier@Retention(Runtime)public @interface SpringBean { @NonBinding String name();}public class SpringBeanProducer { @Produces @SpringBean public Object create(InjectionPoint ip) { // get the name() from the annotation on the injection point String springBeanName = ip.getAnnotations().... //get the ServletContext from the FacesContext ServletContext ctx = FacesContext.getCurrentInstance()... return WebApplicationContextUtils .getRequiredWebApplication(ctx).getBean(springBeanName); }}
然后您可以拥有:
@Inject @SpringBean("fooBean")private Foo yourObject;
PS您可以使以上内容更加类型安全。无需按名称获取bean,而是可以通过反射获取注入点的通用类型,并在spring上下文中进行查找。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)