/** * Create a new PersistenceExceptionTranslationAdvisor. * @param persistenceExceptionTranslator the PersistenceExceptionTranslator to use * @param repositoryAnnotationType the annotation type to check for */ public PersistenceExceptionTranslationAdvisor( PersistenceExceptionTranslator persistenceExceptionTranslator, Class<? extends Annotation> repositoryAnnotationType) { this.advice = new PersistenceExceptionTranslationInterceptor(persistenceExceptionTranslator); this.pointcut = new AnnotationMatchingPointcut(repositoryAnnotationType, true); }
/** * Create a new PersistenceExceptionTranslationAdvisor. * @param beanFactory the ListableBeanFactory to obtaining all * PersistenceExceptionTranslators from * @param repositoryAnnotationType the annotation type to check for */ PersistenceExceptionTranslationAdvisor( ListableBeanFactory beanFactory, Class<? extends Annotation> repositoryAnnotationType) { this.advice = new PersistenceExceptionTranslationInterceptor(beanFactory); this.pointcut = new AnnotationMatchingPointcut(repositoryAnnotationType, true); }
@Override protected void addPersistenceExceptionTranslation(ProxyFactory pf, PersistenceExceptionTranslator pet) { if (AnnotationUtils.findAnnotation(pf.getTargetClass(), Repository.class) != null) { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.registerBeanDefinition("peti", new RootBeanDefinition(PersistenceExceptionTranslationInterceptor.class)); bf.registerSingleton("pet", pet); pf.addAdvice((PersistenceExceptionTranslationInterceptor) bf.getBean("peti")); } }