2017-05-15 15 views
0

我有一个遗留产品的JAR包含Spring(4.3.8)托管类。我需要将它与CDI(JavaEE 7)集成。防止Spring插入CDI注释,即使是工厂创建的实例

我有一个来自传统JAR的接口,它由一个CDI bean实现。 CDI Bean是从CDI BeanManager请求并从工厂方法返回的。工厂方法在Spring XML中注册并按预期工作。

当传统JAR的Spring bean依赖于实现的接口时,会发生问题。 Spring比注入CDI实现实例并扫描其已知注释的类,命名为@Inject。然后它尝试解析依赖项,因为依赖项不可用于Spring,所以依赖项不起作用。

我已经调整了上下文:property-placeholder排除了,但是这并没有改变。

那么我该如何告诉Spring停止尝试在我的工厂生成的bean实例中注入某些东西?

回答

0

我终于能够解决(解决)问题。我必须删除遗留JAR中的所有CDI注解(通过将它们与Spring对应项进行替换),所以春天将继续工作。

然后添加以下XML块到我的CDI WAR的applicationContext.xml中:

<context:component-scan annotation-config="false" base-package="com.example"> 
</context:component-scan> 
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"> 
    <property name="autowiredAnnotationTypes"> 
     <set> 
      <value>org.springframework.beans.factory.annotation.Autowired</value> 
      <value>org.springframework.beans.factory.annotation.Value</value> 
     </set> 
    </property> 
</bean> 
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" /> 
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> 
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" /> 
<bean class="org.springframework.beans.factory.annotation.CustomAutowireConfigurer"> 
    <property name="customQualifierTypes"> 
     <set> 
      <value>org.springframework.beans.factory.annotation.Qualifier</value> 
     </set> 
    </property> 
</bean> 

基本上从春季下降为@注入,支持等,并让它在那里它属于:CDI。