类 PersistenceExceptionTranslationInterceptor
- java.lang.Object
- org.springframework.dao.support.PersistenceExceptionTranslationInterceptor
- 所有已实现的接口:
Advice,Interceptor,MethodInterceptor,Aware,BeanFactoryAware,InitializingBean
public class PersistenceExceptionTranslationInterceptor extends Object implements MethodInterceptor, BeanFactoryAware, InitializingBean
AOP Alliance MethodInterceptor that provides persistence exception translation based on a given PersistenceExceptionTranslator.Delegates to the given
PersistenceExceptionTranslatorto translate a RuntimeException thrown into Spring's DataAccessException hierarchy (if appropriate). If the RuntimeException in question is declared on the target method, it is always propagated as-is (with no translation applied).- 从以下版本开始:
- 2.0
- 作者:
- Rod Johnson, Juergen Hoeller
- 另请参阅:
PersistenceExceptionTranslator
构造器概要
构造器 构造器 说明 PersistenceExceptionTranslationInterceptor()Create a new PersistenceExceptionTranslationInterceptor.PersistenceExceptionTranslationInterceptor(ListableBeanFactory beanFactory)Create a new PersistenceExceptionTranslationInterceptor, autodetecting PersistenceExceptionTranslators in the given BeanFactory.PersistenceExceptionTranslationInterceptor(PersistenceExceptionTranslator pet)Create a new PersistenceExceptionTranslationInterceptor for the given PersistenceExceptionTranslator.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidafterPropertiesSet()Invoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.protected PersistenceExceptionTranslatordetectPersistenceExceptionTranslators(ListableBeanFactory bf)Detect all PersistenceExceptionTranslators in the given BeanFactory.Objectinvoke(MethodInvocation mi)Implement this method to perform extra treatments before and after the invocation.voidsetAlwaysTranslate(boolean alwaysTranslate)Specify whether to always translate the exception ("true"), or whether throw the raw exception when declared, i.e. when the originating method signature's exception declarations allow for the raw exception to be thrown ("false").voidsetBeanFactory(BeanFactory beanFactory)Callback that supplies the owning factory to a bean instance.voidsetPersistenceExceptionTranslator(PersistenceExceptionTranslator pet)Specify the PersistenceExceptionTranslator to use.
构造器详细资料
PersistenceExceptionTranslationInterceptor
public PersistenceExceptionTranslationInterceptor()
Create a new PersistenceExceptionTranslationInterceptor. Needs to be configured with a PersistenceExceptionTranslator afterwards.
PersistenceExceptionTranslationInterceptor
public PersistenceExceptionTranslationInterceptor(PersistenceExceptionTranslator pet)
Create a new PersistenceExceptionTranslationInterceptor for the given PersistenceExceptionTranslator.- 参数:
pet- the PersistenceExceptionTranslator to use
PersistenceExceptionTranslationInterceptor
public PersistenceExceptionTranslationInterceptor(ListableBeanFactory beanFactory)
Create a new PersistenceExceptionTranslationInterceptor, autodetecting PersistenceExceptionTranslators in the given BeanFactory.- 参数:
beanFactory- the ListableBeanFactory to obtaining all PersistenceExceptionTranslators from
方法详细资料
setPersistenceExceptionTranslator
public void setPersistenceExceptionTranslator(PersistenceExceptionTranslator pet)
Specify the PersistenceExceptionTranslator to use.Default is to autodetect all PersistenceExceptionTranslators in the containing BeanFactory, using them in a chain.
setAlwaysTranslate
public void setAlwaysTranslate(boolean alwaysTranslate)
Specify whether to always translate the exception ("true"), or whether throw the raw exception when declared, i.e. when the originating method signature's exception declarations allow for the raw exception to be thrown ("false").Default is "false". Switch this flag to "true" in order to always translate applicable exceptions, independent from the originating method signature.
Note that the originating method does not have to declare the specific exception. Any base class will do as well, even
throws Exception: As long as the originating method does explicitly declare compatible exceptions, the raw exception will be rethrown. If you would like to avoid throwing raw exceptions in any case, switch this flag to "true".
setBeanFactory
public void setBeanFactory(BeanFactory beanFactory) throws BeansException
从接口复制的说明: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.- 指定者:
setBeanFactory在接口中BeanFactoryAware- 参数:
beanFactory- owning BeanFactory (nevernull). The bean can immediately call methods on the factory.- 抛出:
BeansException- in case of initialization errors- 另请参阅:
BeanInitializationException
afterPropertiesSet
public void afterPropertiesSet()
从接口复制的说明:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- 指定者:
afterPropertiesSet在接口中InitializingBean
invoke
public Object invoke(MethodInvocation mi) throws Throwable
从接口复制的说明:MethodInterceptorImplement this method to perform extra treatments before and after the invocation. Polite implementations would certainly like to invokeJoinpoint.proceed().- 指定者:
invoke在接口中MethodInterceptor- 参数:
mi- the method invocation joinpoint- 返回:
- the result of the call to
Joinpoint.proceed(); might be intercepted by the interceptor - 抛出:
Throwable- if the interceptors or the target object throws an exception
detectPersistenceExceptionTranslators
protected PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory bf)
Detect all PersistenceExceptionTranslators in the given BeanFactory.- 参数:
bf- the ListableBeanFactory to obtain PersistenceExceptionTranslators from- 返回:
- a chained PersistenceExceptionTranslator, combining all PersistenceExceptionTranslators found in the given bean factory
- 另请参阅:
ChainedPersistenceExceptionTranslator