2016-06-28 77 views
1

我想重載Springs CommonAnnotationBeanPostProcessor與自定義類(CustomCommonAnnotationBeanPostProcessor),它擴展了CommonAnnotationBeanPostProcessor。如何通過自定義預處理器覆蓋CommonAnnotationBeanPostProcessor

我從文檔中看到有可能這樣做,但我不知道如何去做。

注意:默認的CommonAnnotationBeanPostProcessor將由「context:annotation-config」和「context:component-scan」XML標籤進行註冊。如果您打算指定自定義的CommonAnnotationBeanPostProcessor bean定義,請在那裏刪除或關閉默認的註釋配置!

以前有人做過這個嗎?

回答

1

看後續樣品:

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <context:property-placeholder location="classpath:test.properties"/> 

    <bean class="br.org.energia.csi.scl.batch.spring.configuration.NSCLAnnotationBeanPostProcessor" /> 
    <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /> 
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> 
    <bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" /> 

    <context:component-scan annotation-config="false" base-package="br.org.energia.test"> 
     <context:include-filter type="annotation" expression="javax.ejb.Stateless" /> 
    </context:component-scan> 

該關閉CommonAnnotationBeanPostProcessor會屬性爲 「註解的配置= '假'」。但是當你這樣做時,你需要配置你需要的PostProcessors。