diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJProxyFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJProxyFactory.java index 9f6277ccab..edf1cd3571 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJProxyFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJProxyFactory.java @@ -24,7 +24,7 @@ import org.aspectj.lang.reflect.PerClauseKind; import org.springframework.aop.Advisor; import org.springframework.aop.aspectj.AspectJProxyUtils; -import org.springframework.aop.aspectj.SimpleAspectInstanceFactory; +import org.springframework.aop.framework.AopConfigException; import org.springframework.aop.framework.ProxyCreatorSupport; import org.springframework.aop.support.AopUtils; import org.springframework.core.annotation.AnnotationAwareOrderComparator; @@ -169,8 +169,18 @@ public class AspectJProxyFactory extends ProxyCreatorSupport { // To be safe, check within full lock now... instance = aspectCache.get(aspectClass); if (instance == null) { - instance = new SimpleAspectInstanceFactory(aspectClass).getAspectInstance(); - aspectCache.put(aspectClass, instance); + try { + instance = aspectClass.newInstance(); + aspectCache.put(aspectClass, instance); + } + catch (InstantiationException ex) { + throw new AopConfigException( + "Unable to instantiate aspect class: " + aspectClass.getName(), ex); + } + catch (IllegalAccessException ex) { + throw new AopConfigException( + "Could not access aspect constructor: " + aspectClass.getName(), ex); + } } } } diff --git a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/ArgumentBindingTests.java b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/ArgumentBindingTests.java index 424505004d..08740b5ade 100644 --- a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/ArgumentBindingTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/ArgumentBindingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2016 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,26 +37,26 @@ import static org.junit.Assert.*; * @author Juergen Hoeller * @author Chris Beams */ -public final class ArgumentBindingTests { +public class ArgumentBindingTests { - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testBindingInPointcutUsedByAdvice() { TestBean tb = new TestBean(); AspectJProxyFactory proxyFactory = new AspectJProxyFactory(tb); proxyFactory.addAspect(NamedPointcutWithArgs.class); - ITestBean proxiedTestBean = (ITestBean) proxyFactory.getProxy(); - proxiedTestBean.setName("Supercalifragalisticexpialidocious"); // should throw + ITestBean proxiedTestBean = proxyFactory.getProxy(); + proxiedTestBean.setName("Supercalifragalisticexpialidocious"); } - @Test(expected=IllegalStateException.class) + @Test(expected = IllegalStateException.class) public void testAnnotationArgumentNameBinding() { TransactionalBean tb = new TransactionalBean(); AspectJProxyFactory proxyFactory = new AspectJProxyFactory(tb); proxyFactory.addAspect(PointcutWithAnnotationArgument.class); - ITransactionalBean proxiedTestBean = (ITransactionalBean) proxyFactory.getProxy(); - proxiedTestBean.doInTransaction(); // should throw + ITransactionalBean proxiedTestBean = proxyFactory.getProxy(); + proxiedTestBean.doInTransaction(); } @Test @@ -71,6 +71,7 @@ public final class ArgumentBindingTests { assertEquals("formal", pnames[0]); } + public void methodWithOneParam(String aParam) { } @@ -100,9 +101,6 @@ public final class ArgumentBindingTests { } -/** - * @author Juergen Hoeller - */ @Aspect class PointcutWithAnnotationArgument { @@ -115,9 +113,6 @@ class PointcutWithAnnotationArgument { } -/** - * @author Adrian Colyer - */ @Aspect class NamedPointcutWithArgs {