Announcement Announcement Module
Collapse
No announcement yet.
Aspect doesn't not work with 2.1m2 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Aspect doesn't not work with 2.1m2

    Hi,

    I made a small AOP example (see bellow), this example works fine with springframework 2.1m1 but not with 2.1m2. With 2.1m2 the Aspect is not called.

    Any idea?

    Pom dependencies:
    Code:
      <dependencies>
      	<dependency>
      		<groupId>org.springframework</groupId>
      		<artifactId>spring</artifactId>
      		<version>2.1-m1</version>
      	</dependency>
      	<dependency>
      		<groupId>asm</groupId>
      		<artifactId>asm</artifactId>
      		<version>2.2.3</version>
      	</dependency>
      	<dependency>
      		<groupId>asm</groupId>
      		<artifactId>asm-commons</artifactId>
      		<version>2.2.3</version>
      	</dependency>
      	<dependency>
      		<groupId>org.springframework</groupId>
      		<artifactId>spring-aspects</artifactId>
      		<version>2.1-m1</version>
      	</dependency>
      	<dependency>
      		<groupId>org.unitils</groupId>
      		<artifactId>unitils</artifactId>
      		<version>1.0-rc-3</version>
      		<scope>test</scope>
      	</dependency>
      	<dependency>
      		<groupId>junit</groupId>
      		<artifactId>junit</artifactId>
      		<version>4.0</version>
      		<scope>test</scope>
      	</dependency>
      </dependencies>
    My applicationContext is:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.1.xsd http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-2.1.xsd">
    
    	<aop:aspectj-autoproxy />
    
    	<context:component-scan base-package="com"/>
    
    </beans>
    My aspect is:

    Code:
    @Aspect
    public class MyAspect {
    
    	private Log log = LogFactory.getLog(MyAspect.class);
    
    	@Pointcut("execution(public * helloWorld(..))")
    	private void anyPublicOperation() {
    	}
    
    	@Before("anyPublicOperation()")
    	public void doBeforeAnyPublicOperation() {
    		log.debug("doBeforeAnyPublicOperation");
    	}
    	@After("anyPublicOperation()")
    	public void doAfterAnyPublicOperation() {
    		log.debug("doAfterAnyPublicOperation");
    	}
    
    	@Around("anyPublicOperation()")
    	public void doAroundAnyPublicOperation(ProceedingJoinPoint pjp)
    			throws Throwable {
    		log.debug("Start time:" + new Date());
    		pjp.proceed();
    		log.debug("End time:" + new Date());
    	}
    
    }
    and my bean is:

    Code:
    @Component
    public class MyBean implements IMyBean {
    	private Log log = LogFactory.getLog(MyBean.class);
    
    	
    	public void helloWorld() {
    		log.debug("Hello World");
    	}
    
    }

  • #2
    Hi,

    as I already said in the Spring IDE forum the behavior you are seeing is "by design". With 2.1 m2 @Aspect annotation classes are not automatically picked up by the component scan facility (any more). This has been changed by Juergen, so I guess that is intentionally.

    You need to add the following to your config:
    Code:
        <context:component-scan base-package="com" use-default-filters="true" >
            <context:include-filter type="annotation" expression="org.aspectj.lang.annotation.Aspect"/>
        </context:component-scan>
    Christian

    Comment


    • #3
      Have any of you managed to make it work? I added context:include-filter and still no luck with method interception

      Comment


      • #4
        cdupuis: I think that there is a bit of misunderstanding here

        I have an aspect and a component.
        If the component is defined via .xml configuration file, the method interception works.

        However, when I define my component via @Component annotation, the interception suddenly stops working.

        This has nothing to do with component scan filtering (I suppose...)

        What you proposed just makes the @Aspect annotated classes created in the application context by default.

        Anyway, does anybody know why the Aspect doesn't get fired on @Component created classes?

        Comment

        Working...
        X