Search in sources :

Example 1 with PersistenceExceptionTranslationPostProcessor

use of org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor in project spring-boot by spring-projects.

the class PersistenceExceptionTranslationAutoConfiguration method persistenceExceptionTranslationPostProcessor.

@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;
}
Also used : PersistenceExceptionTranslationPostProcessor(org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Example 2 with PersistenceExceptionTranslationPostProcessor

use of org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor in project spring-boot by spring-projects.

the class PersistenceExceptionTranslationAutoConfiguration method persistenceExceptionTranslationPostProcessor.

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "spring.dao.exceptiontranslation", name = "enabled", matchIfMissing = true)
public static PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor(Environment environment) {
    PersistenceExceptionTranslationPostProcessor postProcessor = new PersistenceExceptionTranslationPostProcessor();
    boolean proxyTargetClass = environment.getProperty("spring.aop.proxy-target-class", Boolean.class, Boolean.TRUE);
    postProcessor.setProxyTargetClass(proxyTargetClass);
    return postProcessor;
}
Also used : PersistenceExceptionTranslationPostProcessor(org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Example 3 with PersistenceExceptionTranslationPostProcessor

use of org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor in project spring-boot by spring-projects.

the class PersistenceExceptionTranslationAutoConfigurationTests method exceptionTranslationPostProcessorCanBeConfiguredToUseJdkProxy.

@Test
void exceptionTranslationPostProcessorCanBeConfiguredToUseJdkProxy() {
    this.context = new AnnotationConfigApplicationContext();
    TestPropertyValues.of("spring.aop.proxy-target-class=false").applyTo(this.context);
    this.context.register(PersistenceExceptionTranslationAutoConfiguration.class);
    this.context.refresh();
    Map<String, PersistenceExceptionTranslationPostProcessor> beans = this.context.getBeansOfType(PersistenceExceptionTranslationPostProcessor.class);
    assertThat(beans).hasSize(1);
    assertThat(beans.values().iterator().next().isProxyTargetClass()).isFalse();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PersistenceExceptionTranslationPostProcessor(org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor) Test(org.junit.jupiter.api.Test)

Example 4 with PersistenceExceptionTranslationPostProcessor

use of org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor in project spring-boot by spring-projects.

the class PersistenceExceptionTranslationAutoConfigurationTests method exceptionTranslationPostProcessorBeanIsCreated.

@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();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PersistenceExceptionTranslationPostProcessor(org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor) Test(org.junit.Test)

Example 5 with PersistenceExceptionTranslationPostProcessor

use of org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor in project spring-boot by spring-projects.

the class PersistenceExceptionTranslationAutoConfigurationTests method exceptionTranslationPostProcessorBeanIsDisabled.

@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();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PersistenceExceptionTranslationPostProcessor(org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor) Test(org.junit.Test)

Aggregations

PersistenceExceptionTranslationPostProcessor (org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor)7 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 Test (org.junit.jupiter.api.Test)3 Test (org.junit.Test)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)2 Bean (org.springframework.context.annotation.Bean)2