【问题标题】:How to override CommonAnnotationBeanPostProcessor by custom preprocessor如何通过自定义预处理器覆盖 CommonAnnotationBeanPostProcessor
【发布时间】:2016-10-31 08:49:48
【问题描述】:

我正在尝试使用扩展 CommonAnnotationBeanPostProcessor 的自定义类 (CustomCommonAnnotationBeanPostProcessor) 覆盖 SpringsCommonAnnotationBeanPostProcessor。

我从文档中看到可以这样做,但我不知道该怎么做。

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

以前有人做过吗?

【问题讨论】:

    标签: spring spring-mvc


    【解决方案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'”。但是当你这样做时,你需要配置你需要的后处理器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-17
      • 1970-01-01
      • 2012-02-19
      • 2017-03-25
      • 2021-11-27
      相关资源
      最近更新 更多