sanket shah
sanket shah

Reputation: 21

How to override CommonAnnotationBeanPostProcessor by custom preprocessor

I am trying to override Springs CommonAnnotationBeanPostProcessor with a custom class (CustomCommonAnnotationBeanPostProcessor) which extends CommonAnnotationBeanPostProcessor.

I see from the document that it is possible to do it, but I am not sure how to.

NOTE: A default CommonAnnotationBeanPostProcessor will be registered by the "context:annotation-config" and "context:component-scan" XML tags. Remove or turn off the default annotation configuration there if you intend to specify a custom CommonAnnotationBeanPostProcessor bean definition!

Has anybody done this before?

Upvotes: 1

Views: 690

Answers (1)

Valdir Scarin
Valdir Scarin

Reputation: 31

Look the follow sample:

<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>

The attribute that turn off CommonAnnotationBeanPostProcessor is "annotation-config='false'". But when you do that, you need configure the PostProcessors that you need.

Upvotes: 1

Related Questions