Results 1 to 2 of 2

Thread: Newbie question

  1. #1
    Join Date
    Jul 2006
    Posts
    24

    Default Newbie question

    Can I mix and match @Aspect with XML configuration? In other words, if I have defined the following:

    <beans>
    <context:annotation-config/>
    <context:component-scan base-package="com.mytest"/>

    <aop:aspectj-autoproxy/>
    .....

    <!-- Sample Service Bean -->
    <bean id="myService" class="com.mytest.TestServiceImpl"/>
    <!-- Implements the same interface as myservice. -->
    <bean id="myService2" class="com.mytest.TestServiceImpl2"/>
    </beans>

    The impl classes have been defined with @Service tag as well.

    public interface Test {
    public void echo();
    }

    @Service
    public class TestServiceImpl implements Test {
    public void echo() {
    System.out.println("Primary");
    }

    @Service
    public class TestServiceImpl2 implements Test {
    public void echo() {
    System.out.println("Primary2");
    }


    If I define my aspect with the @Aspect notation, but I do not see the aspect being applied. If I remove the bean definitions from the XML file and ensure there is only one implementation of the interface, then the aspect is applied to the Service Impl.

    What am I missing? Thanks in advance.

  2. #2
    Join Date
    Jul 2006
    Posts
    24

    Default Maybe not clear enough

    My simple Performance monitor does the following:
    Code:
    @Component
    @Aspect
    public class ServicePerformanceCheck {
        @Pointcut("execution(* com.mytest.*.*(..))")
        public void businessService() {}
    
        @Around("businessService()")
        public Object monitor(ProceedingJoinPoint pjp) throws Throwable {
    	StopWatch clock = new StopWatch(pjp.toShortString());
    	clock.start();
            try {
                return pjp.proceed();
            } finally {
                clock.stop();
                System.out.println(clock.prettyPrint());
                
            }
        }
    }
    So what happens is that for the beans declared in XML, the performance monitor does not log the metric. However, if the bean definitions are removed from the XML configuration and we just depend on the @Service tags, the metrics are logged.

    So it looks to me like I cannot mix the @Aspect with plain XML configured beans. Is this accurate or am I missing something?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •