Make default proxyTargetClass=false

If the default is true JPA repositories all have to have
default constructors etc.
pull/77/merge
Dave Syer 11 years ago
parent c6e0c76341
commit bbec4f7cf5

@ -37,13 +37,13 @@ public class AopAutoConfiguration {
@Configuration @Configuration
@EnableAspectJAutoProxy(proxyTargetClass = false) @EnableAspectJAutoProxy(proxyTargetClass = false)
@ConditionalOnExpression("!${spring.aop.proxyTargetClass:true}") @ConditionalOnExpression("!${spring.aop.proxyTargetClass:false}")
public static class JdkDynamicAutoProxyConfiguration { public static class JdkDynamicAutoProxyConfiguration {
} }
@Configuration @Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true) @EnableAspectJAutoProxy(proxyTargetClass = true)
@ConditionalOnExpression("${spring.aop.proxyTargetClass:true}") @ConditionalOnExpression("${spring.aop.proxyTargetClass:false}")
public static class CglibAutoProxyConfiguration { public static class CglibAutoProxyConfiguration {
} }

@ -16,18 +16,18 @@
package org.springframework.boot.autoconfigure.aop; package org.springframework.boot.autoconfigure.aop;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.TestUtils; import org.springframework.boot.TestUtils;
import org.springframework.boot.autoconfigure.aop.AopAutoConfigurationTests.TestInterface; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link AopAutoConfiguration}. * Tests for {@link AopAutoConfiguration}.
* *
@ -43,12 +43,26 @@ public class AopAutoConfigurationTests {
private AnnotationConfigApplicationContext context; private AnnotationConfigApplicationContext context;
@Test
public void testNoAopAutoConfiguration() {
this.context = new AnnotationConfigApplicationContext();
this.context.register(TestConfiguration.class, AopAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
TestUtils.addEnviroment(this.context, "spring.aop.auto:false");
this.context.refresh();
TestAspect aspect = this.context.getBean(TestAspect.class);
assertFalse(aspect.isCalled());
TestBean bean = this.context.getBean(TestBean.class);
bean.foo();
assertFalse(aspect.isCalled());
}
@Test @Test
public void testAopAutoConfigurationProxyTargetClass() { public void testAopAutoConfigurationProxyTargetClass() {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context.register(TestConfiguration.class, AopAutoConfiguration.class); this.context.register(TestConfiguration.class, AopAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
TestUtils.addEnviroment(this.context, "spring.aop.proxyTargetClass:true"); TestUtils.addEnviroment(this.context, "spring.aop.proxyTargetClass:true");
TestUtils.addEnviroment(this.context, "spring.aop.auto:true");
this.context.refresh(); this.context.refresh();
TestAspect aspect = this.context.getBean(TestAspect.class); TestAspect aspect = this.context.getBean(TestAspect.class);
assertFalse(aspect.isCalled()); assertFalse(aspect.isCalled());
@ -57,13 +71,12 @@ public class AopAutoConfigurationTests {
assertTrue(aspect.isCalled()); assertTrue(aspect.isCalled());
} }
@Test @Test
public void testAopAutoConfigurationNoProxyTargetClass() { public void testAopAutoConfigurationNoProxyTargetClass() {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context.register(TestConfiguration.class, AopAutoConfiguration.class); this.context.register(TestConfiguration.class, AopAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
TestUtils.addEnviroment(this.context, "spring.aop.proxyTargetClass:false"); TestUtils.addEnviroment(this.context, "spring.aop.proxyTargetClass:false");
TestUtils.addEnviroment(this.context, "spring.aop.auto:true");
this.context.refresh(); this.context.refresh();
TestAspect aspect = this.context.getBean(TestAspect.class); TestAspect aspect = this.context.getBean(TestAspect.class);
assertFalse(aspect.isCalled()); assertFalse(aspect.isCalled());
@ -78,6 +91,7 @@ public class AopAutoConfigurationTests {
public TestAspect aspect() { public TestAspect aspect() {
return new TestAspect(); return new TestAspect();
} }
@Bean @Bean
public TestInterface bean() { public TestInterface bean() {
return new TestBean(); return new TestBean();
@ -95,12 +109,12 @@ public class AopAutoConfigurationTests {
private boolean called; private boolean called;
public boolean isCalled() { public boolean isCalled() {
return called; return this.called;
} }
@Before("execution(* foo(..))") @Before("execution(* foo(..))")
public void before() { public void before() {
called=true; this.called = true;
} }
} }

Loading…
Cancel
Save