spring-framework / org.springframework.aop.framework.autoproxy / AbstractBeanFactoryAwareAdvisingPostProcessor

AbstractBeanFactoryAwareAdvisingPostProcessor

abstract class AbstractBeanFactoryAwareAdvisingPostProcessor : AbstractAdvisingBeanPostProcessor, BeanFactoryAware

Extension of AbstractAutoProxyCreator which implements BeanFactoryAware, adds exposure of the original target class for each proxied bean (AutoProxyUtils#ORIGINAL_TARGET_CLASS_ATTRIBUTE), and participates in an externally enforced target-class mode for any given bean (AutoProxyUtils#PRESERVE_TARGET_CLASS_ATTRIBUTE). This post-processor is therefore aligned with AbstractAutoProxyCreator.

Author
Juergen Hoeller

Since
4.2.3

See Also
AutoProxyUtils#shouldProxyTargetClassAutoProxyUtils#determineTargetClass

Constructors

<init>

AbstractBeanFactoryAwareAdvisingPostProcessor()

Extension of AbstractAutoProxyCreator which implements BeanFactoryAware, adds exposure of the original target class for each proxied bean (AutoProxyUtils#ORIGINAL_TARGET_CLASS_ATTRIBUTE), and participates in an externally enforced target-class mode for any given bean (AutoProxyUtils#PRESERVE_TARGET_CLASS_ATTRIBUTE). This post-processor is therefore aligned with AbstractAutoProxyCreator.

Functions

setBeanFactory

open fun setBeanFactory(beanFactory: BeanFactory): Unit

Inherited Functions

postProcessAfterInitialization

open fun postProcessAfterInitialization(bean: Any, beanName: String): Any

postProcessBeforeInitialization

open fun postProcessBeforeInitialization(bean: Any, beanName: String): Any

setBeforeExistingAdvisors

open fun setBeforeExistingAdvisors(beforeExistingAdvisors: Boolean): Unit

Set whether this post-processor's advisor is supposed to apply before existing advisors when encountering a pre-advised object.

Default is "false", applying the advisor after existing advisors, i.e. as close as possible to the target method. Switch this to "true" in order for this post-processor's advisor to wrap existing advisors as well.

Note: Check the concrete post-processor's javadoc whether it possibly changes this flag by default, depending on the nature of its advisor.

Inheritors

MethodValidationPostProcessor

open class MethodValidationPostProcessor : AbstractBeanFactoryAwareAdvisingPostProcessor, InitializingBean

A convenient BeanPostProcessor implementation that delegates to a JSR-303 provider for performing method-level validation on annotated methods.

Applicable methods have JSR-303 constraint annotations on their parameters and/or on their return value (in the latter case specified at the method level, typically as inline annotation), e.g.:

 public @NotNull Object myValidMethod(@NotNull String arg1, @Max(10) int arg2) 

Target classes with such annotated methods need to be annotated with Spring's Validated annotation at the type level, for their methods to be searched for inline constraint annotations. Validation groups can be specified through @Validated as well. By default, JSR-303 will validate against its default group only.

As of Spring 5.0, this functionality requires a Bean Validation 1.1 provider.

PersistenceExceptionTranslationPostProcessor

open class PersistenceExceptionTranslationPostProcessor : AbstractBeanFactoryAwareAdvisingPostProcessor

Bean post-processor that automatically applies persistence exception translation to any bean marked with Spring's @org.springframework.stereotype.Repository annotation, adding a corresponding PersistenceExceptionTranslationAdvisor to the exposed proxy (either an existing AOP proxy or a newly generated proxy that implements all of the target's interfaces).

Translates native resource exceptions to Spring's org.springframework.dao.DataAccessException hierarchy. Autodetects beans that implement the org.springframework.dao.support.PersistenceExceptionTranslator interface, which are subsequently asked to translate candidate exceptions.

All of Spring's applicable resource factories (e.g. org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) implement the PersistenceExceptionTranslator interface out of the box. As a consequence, all that is usually needed to enable automatic exception translation is marking all affected beans (such as Repositories or DAOs) with the @Repository annotation, along with defining this post-processor as a bean in the application context.