Merge branch '1.5.x'

pull/8889/head
Stephane Nicoll 8 years ago
commit d3f180b664

@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,7 +20,9 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
/**
@ -28,6 +30,7 @@ import org.springframework.dao.annotation.PersistenceExceptionTranslationPostPro
* translation.
*
* @author Andy Wilkinson
* @author Stephane Nicoll
* @since 1.2.0
*/
@ConditionalOnClass(PersistenceExceptionTranslationPostProcessor.class)
@ -36,10 +39,18 @@ public class PersistenceExceptionTranslationAutoConfiguration {
@Bean
@ConditionalOnMissingBean(PersistenceExceptionTranslationPostProcessor.class)
@ConditionalOnProperty(prefix = "spring.dao.exceptiontranslation", name = "enabled", matchIfMissing = true)
public static PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor() {
public static PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor(
Environment environment) {
PersistenceExceptionTranslationPostProcessor postProcessor = new PersistenceExceptionTranslationPostProcessor();
postProcessor.setProxyTargetClass(true);
postProcessor.setProxyTargetClass(determineProxyTargetClass(environment));
return postProcessor;
}
private static boolean determineProxyTargetClass(Environment environment) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment,
"spring.aop.");
Boolean value = resolver.getProperty("proxyTargetClass", Boolean.class);
return (value != null ? value : true);
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -37,10 +37,10 @@ import org.springframework.stereotype.Repository;
import static org.assertj.core.api.Assertions.assertThat;
/**
*
* Tests for {@link PersistenceExceptionTranslationAutoConfiguration}
*
* @author Andy Wilkinson
* @author Stephane Nicoll
*/
public class PersistenceExceptionTranslationAutoConfigurationTests {
@ -54,7 +54,7 @@ public class PersistenceExceptionTranslationAutoConfigurationTests {
}
@Test
public void exceptionTranslationPostProcessorBeanIsCreated() {
public void exceptionTranslationPostProcessorUsesCglibByDefault() {
this.context = new AnnotationConfigApplicationContext(
PersistenceExceptionTranslationAutoConfiguration.class);
Map<String, PersistenceExceptionTranslationPostProcessor> beans = this.context
@ -64,7 +64,20 @@ public class PersistenceExceptionTranslationAutoConfigurationTests {
}
@Test
public void exceptionTranslationPostProcessorBeanIsDisabled() {
public void exceptionTranslationPostProcessorCanBeConfiguredToUseJdkProxy() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.aop.proxyTargetClass=false");
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();
}
@Test
public void exceptionTranslationPostProcessorCanBeDisabled() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.dao.exceptiontranslation.enabled=false");

Loading…
Cancel
Save