Spring AOP (Aspect) Not executing

I'm not sure if I did it properly but for me what solved it was adding @Component to the "Aspect'ed" class -

@Aspect
@Component
public class PerformanceLogger {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Around("within(com.something.rest.service..*)")
    public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();
        Object retVal = pjp.proceed();
        long end = System.currentTimeMillis();
        logger.debug(pjp.getSignature().toShortString() + " Finish: " + (end - start) + "ms");
        return retVal;
    }
}

(And just to close the loop - if you are using annotation based, don't forget adding @EnableAspectJAutoProxy to your Config class.

@EnableAspectJAutoProxy

For those who opted for JavaConfig, you can declare your Aspect as a bean and add the @EnableAspectJAutoProxy annotation to turn on auto-proxying :

@Configuration
@EnableAspectJAutoProxy
@ComponentScan
public class MyConfig {
    @Bean
    public LoggingAspect loggingAspect(){
        return new LoggingAspect();
    }
}

Finally SOLVED it.

I think I was missing aspectj-maven-plugin. It required for spring to weaving of aspects. None tutorial provide this information though. Added following to my pom.xml.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.0</version>
    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>1.6.1</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
                <goal>test-compile</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <outxml>true</outxml>
        <verbose>true</verbose>
        <showWeaveInfo>true</showWeaveInfo>
        <aspectLibraries>
            <aspectLibrary>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aspects</artifactId>
            </aspectLibrary>
        </aspectLibraries>
        <source>1.6</source>
        <target>1.6</target>
    </configuration>
</plugin>

Thanks guys


If you havent tried already...try the xml based spring-aop configuration as follows:

    <aop:config>
    <aop:aspect ref="loggingAspect">
        <aop:pointcut expression="execution(* uk.co.txttools.web.controller.compose.PreviewMessageController.set*(..))" id="previewMessageControllerSetters"/>
        <aop:before method="setLoggingAdvice" pointcut-ref="previewMessageControllerSetters"/>

         // set other 2 pointcuts similarly....
        </aop:aspect>       
    </aop:config>
    <bean id="loggingAspect" class="uk.co.txttools.aspects.LoggingAspect" />