Pascal是对的,你不能将spring管理的东西注入到焊接bean中(反之亦然)。
但是你可以定义一个生产者,该生产者获取春豆并将其提供给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上下文中进行查找。



