Search code examples
javaspringaopaspectjspring-aop

Spring-boot-aop project cannot create PointCut (Pointcut is not wellformed exception)


trying to build simple aop project

error is Caused by: java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting >>>'(' at character position 0

p1

all imports and packages are correct i double checked.

@Aspect
@Component
public class TxService {

@Pointcut("execution(public void com.boot.aop.dao.EmployeeDao.saveEmployee())")
public void p1() {
    
}
        
@Before("p1")
public void beginTx() {  // advice
        
    System.out.println("Transaction is started");
}

Solution

  • As the error message says, the pointcut is not well-formed. To be more precise, the pointcut reference is not. The actual pointcut looks OK. Please use:

    @Before("p1()")
    

    Do not forget the parentheses! 😉