如何通过自定义预处理器

时间:2016-06-28 20:55:47

标签: spring spring-mvc

我试图用自定义类(CustomCommonAnnotationBeanPostProcessor)覆盖Springs CommonAnnotationBeanPostProcessor ,该类扩展了CommonAnnotationBeanPostProcessor。

我从文件中看到可以做到这一点,但我不知道该怎么做。

  

注意:默认的CommonAnnotationBeanPostProcessor将由“context:annotation-config”和“context:component-scan”XML标记注册。如果要指定自定义CommonAnnotationBeanPostProcessor bean定义,请删除或关闭默认注释配置!

以前有人这样做过吗?

1 个答案:

答案 0 :(得分: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的属性是“annotation-config ='false'”。但是当你这样做时,你需要配置你需要的PostProcessors。