@Bean @ConditionalOnMissingBean(PersistenceExceptionTranslationPostProcessor.class) @ConditionalOnProperty(prefix = "spring.dao.exceptiontranslation", name = "enabled", matchIfMissing = true) public static PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor() { PersistenceExceptionTranslationPostProcessor postProcessor = new PersistenceExceptionTranslationPostProcessor(); postProcessor.setProxyTargetClass(true); return postProcessor; }
@Test public void exceptionTranslationPostProcessorBeanIsCreated() { this.context = new AnnotationConfigApplicationContext( PersistenceExceptionTranslationAutoConfiguration.class); Map<String, PersistenceExceptionTranslationPostProcessor> beans = this.context .getBeansOfType(PersistenceExceptionTranslationPostProcessor.class); assertThat(beans).hasSize(1); assertThat(beans.values().iterator().next().isProxyTargetClass()).isTrue(); }
@Test public void exceptionTranslationPostProcessorBeanIsDisabled() { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "spring.dao.exceptiontranslation.enabled=false"); this.context.register(PersistenceExceptionTranslationAutoConfiguration.class); this.context.refresh(); Map<String, PersistenceExceptionTranslationPostProcessor> beans = this.context .getBeansOfType(PersistenceExceptionTranslationPostProcessor.class); assertThat(beans.entrySet()).isEmpty(); }
@Bean public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { return new PersistenceExceptionTranslationPostProcessor(); }
@Test public void exceptionTranslationPostProcessorBeanIsCreated() { this.context = new AnnotationConfigApplicationContext( PersistenceExceptionTranslationAutoConfiguration.class); Map<String, PersistenceExceptionTranslationPostProcessor> beans = this.context .getBeansOfType(PersistenceExceptionTranslationPostProcessor.class); assertThat(beans.size(), is(equalTo(1))); assertThat(beans.values().iterator().next().isProxyTargetClass(), equalTo(true)); }
@Test public void exceptionTranslationPostProcessorBeanIsDisabled() { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "spring.dao.exceptiontranslation.enabled=false"); this.context.register(PersistenceExceptionTranslationAutoConfiguration.class); this.context.refresh(); Map<String, PersistenceExceptionTranslationPostProcessor> beans = this.context .getBeansOfType(PersistenceExceptionTranslationPostProcessor.class); assertThat(beans.entrySet(), empty()); }
@RefreshScope @Bean public PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor() { return new PersistenceExceptionTranslationPostProcessor(); }
@RefreshScope @Bean public PersistenceExceptionTranslationPostProcessor persistenceMfaTrustedAuthnExceptionTranslationPostProcessor() { return new PersistenceExceptionTranslationPostProcessor(); }
@Bean public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){ return new PersistenceExceptionTranslationPostProcessor(); }
/** * Bean that translates SQL exceptions into Spring unified data-access exceptions * @return Bean */ @Bean public BeanPostProcessor persistenceTranslation(){ return new PersistenceExceptionTranslationPostProcessor(); }
@Bean public PersistenceExceptionTranslationPostProcessor exceptionTranslator() { return new PersistenceExceptionTranslationPostProcessor(); }
@Bean public PersistenceExceptionTranslationPostProcessor exceptionTranslationPostProcessor() { return new PersistenceExceptionTranslationPostProcessor(); }
@Bean public PersistenceExceptionTranslationPostProcessor peTranslationPostProcessor() { return new PersistenceExceptionTranslationPostProcessor(); }
@Bean public BeanPostProcessor persistenceTranslation() { return new PersistenceExceptionTranslationPostProcessor(); }