[jboss-user] [JBoss AOP] - Aspect scope and construction pointcuts

chrismeadows do-not-reply at jboss.com
Wed Nov 1 12:36:11 EST 2006


AOP 1.5.2 libs being used
I'm having problems with construction pointcuts and PER_INSTANCE scope. All other scopes work as expected, but it is PER_INSTANCE that I need.


@Aspect(scope=Scope.PER_INSTANCE)
public class MyAspect {
  
  private static final Logger log = Logger.getLogger(MyAspect.class);
    
  @Bind (pointcut="construction(public MyAspected->new())")
  public Object constructorAdvice(ConstructionInvocation invocation) throws Throwable {
    Object master = invocation.invokeNext();
    log.info("Constructed Aspect");
    return master;
  }
}

--

public class MyAspected {

  private static Logger log = Logger.getLogger( MyAspected.class );
  public MyAspected() {
    log.info("Constructed");
  }
}

--

public class TestMyAspected extends TestCase {

  static {
    BasicConfigurator.configure();
  }

  public void testMyAspected() {
    MyAspected ta = new MyAspected();
  }
}


All scopes work correctly except PER_INSTANCE. With that scope, I get a nasty exception which looks like the AOP framework couldn't find the Advice for the aspected constructor.


java.lang.RuntimeException: Should Be Unreachable, but unable to discover Advice
	at org.jboss.aop.advice.AbstractAdvice.resolveAdvice(AbstractAdvice.java:292)
	at org.jboss.aop.advice.PerInstanceAdvice.invoke(PerInstanceAdvice.java:125)
	at org.jboss.aop.joinpoint.ConstructionInvocation.invokeNext(ConstructionInvocation.java:78)
	at MyAspected.(MyAspected.java:10)
	at TestMyAspected.testMyAspected(TestMyAspected.java:16)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:164)
	at junit.framework.TestCase.runBare(TestCase.java:130)
	at junit.framework.TestResult$1.protect(TestResult.java:110)
	at junit.framework.TestResult.runProtected(TestResult.java:128)
	at junit.framework.TestResult.run(TestResult.java:113)
	at junit.framework.TestCase.run(TestCase.java:120)
	at junit.framework.TestSuite.runTest(TestSuite.java:228)
	at junit.framework.TestSuite.run(TestSuite.java:223)


Any ideas?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3982420#3982420

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3982420



More information about the jboss-user mailing list