Class PersistenceExceptionTranslationPostProcessor
- java.lang.Object
- org.springframework.aop.framework.ProxyConfig
- org.springframework.aop.framework.ProxyProcessorSupport
- org.springframework.aop.framework.AbstractAdvisingBeanPostProcessor
- org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor
- org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
- All Implemented Interfaces:
Serializable,AopInfrastructureBean,Aware,BeanClassLoaderAware,BeanFactoryAware,BeanPostProcessor,Ordered
public class PersistenceExceptionTranslationPostProcessor extends AbstractBeanFactoryAwareAdvisingPostProcessor
Bean post-processor that automatically applies persistence exception translation to any bean marked with Spring's @Repositoryannotation, adding a correspondingPersistenceExceptionTranslationAdvisorto 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
DataAccessExceptionhierarchy. Autodetects beans that implement thePersistenceExceptionTranslatorinterface, which are subsequently asked to translate candidate exceptions.All of Spring's applicable resource factories (e.g.
LocalContainerEntityManagerFactoryBean) implement thePersistenceExceptionTranslatorinterface 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@Repositoryannotation, along with defining this post-processor as a bean in the application context.- Since:
- 2.0
- Author:
- Rod Johnson, Juergen Hoeller
- See Also:
PersistenceExceptionTranslationAdvisor,Repository,DataAccessException,PersistenceExceptionTranslator, Serialized Form
Field Summary
Fields inherited from class org.springframework.aop.framework.AbstractAdvisingBeanPostProcessor
advisor, beforeExistingAdvisors
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor Summary
Constructors Constructor Description PersistenceExceptionTranslationPostProcessor()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidsetBeanFactory(BeanFactory beanFactory)Callback that supplies the owning factory to a bean instance.voidsetRepositoryAnnotationType(Class<? extends Annotation> repositoryAnnotationType)Set the 'repository' annotation type.Methods inherited from class org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor
prepareProxyFactory
Methods inherited from class org.springframework.aop.framework.AbstractAdvisingBeanPostProcessor
customizeProxyFactory, isEligible, isEligible, postProcessAfterInitialization, postProcessBeforeInitialization, setBeforeExistingAdvisors
Methods inherited from class org.springframework.aop.framework.ProxyProcessorSupport
evaluateProxyInterfaces, getOrder, getProxyClassLoader, isConfigurationCallbackInterface, isInternalLanguageInterface, setBeanClassLoader, setOrder, setProxyClassLoader
Methods inherited from class org.springframework.aop.framework.ProxyConfig
copyFrom, isExposeProxy, isFrozen, isOpaque, isOptimize, isProxyTargetClass, setExposeProxy, setFrozen, setOpaque, setOptimize, setProxyTargetClass, toString
Constructor Detail
PersistenceExceptionTranslationPostProcessor
public PersistenceExceptionTranslationPostProcessor()
Method Detail
setRepositoryAnnotationType
public void setRepositoryAnnotationType(Class<? extends Annotation> repositoryAnnotationType)
Set the 'repository' annotation type. The default repository annotation type is theRepositoryannotation.This setter property exists so that developers can provide their own (non-Spring-specific) annotation type to indicate that a class has a repository role.
- Parameters:
repositoryAnnotationType- the desired annotation type
setBeanFactory
public void setBeanFactory(BeanFactory beanFactory)
Description copied from interface:BeanFactoryAwareCallback that supplies the owning factory to a bean instance.Invoked after the population of normal bean properties but before an initialization callback such as
InitializingBean.afterPropertiesSet()or a custom init-method.- Specified by:
setBeanFactoryin interfaceBeanFactoryAware- Overrides:
setBeanFactoryin classAbstractBeanFactoryAwareAdvisingPostProcessor- Parameters:
beanFactory- owning BeanFactory (nevernull). The bean can immediately call methods on the factory.- See Also:
BeanInitializationException