Aldo Suwandi
Aldo Suwandi

Reputation: 392

Spring AOP Pointcut not called

i work with JSF 2.2 + Spring framework 3.2.4

So, i have this applicationContent.xml

<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:p="http://www.springframework.org/schema/p"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.2.xsd 
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx.xsd">

    <aop:aspectj-autoproxy proxy-target-class="true" />
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <context:annotation-config/>
    <context:component-scan base-package="com.vulcan.controller" />
    <context:component-scan base-package="com.vulcan.service" />
    <context:component-scan base-package="com.vulcan.dao" />
    <context:component-scan base-package="com.vulcan.spring.aop" />

.....

Then i have aspect component in

package com.vulcan.spring.aop;

@Aspect
public class LoggingService {
    private Log log = LogFactory.getLog(this.getClass());

    @Pointcut("execution(* *.*(..))")
    protected void loggingOperation() {}

    @Before("loggingOperation()")
    public void logJoinPoint()
    {
        System.out.println ("Hello");
     }
   ....

With this type of execution i assume this pointcut will be triggered on every methods. But the problem is, this pointcut isn't triggered ? Any idea why ? Thanks

FYI, i using glassfish 4, and when i deploy my web app i didn't receive any error configuration. So i assume my configuration is fine.

Upvotes: 2

Views: 9178

Answers (2)

M. Deinum
M. Deinum

Reputation: 125292

@Aspect annotate classes aren't automatically detected by Spring and because it isn't detected it isn't known to the <aop:aspectj-autoproxy /> beans. So basically there is no aspect.

Either add @Component to your @Aspect annotated class(es) so that Spring can detect and use the aspect.

@Compopnent
@Aspect
public class LoggingService { ... }

or declare the aspect explictly in your xml file

<bean class="LoggingService" />

Either way the aspect will be picked up by the <aop:aspectj-autoproxy /> beans and the advice will be run.

Upvotes: 15

user2550754
user2550754

Reputation: 905

Try using execution(* *(..)).

Upvotes: -3

Related Questions