I am doing a springboot project that includes login and accounts. I am trying to @Pointcut
all controller method calls and validate the login information, and @Before
the pointcut to make sure the session exists. Hence the code:
@Aspect @Component public class AuthAspect { Logger logger = LoggerFactory.getLogger(AuthAspect.class); @Pointcut("execution(* show.xianwu.game.frisbeescorer.controller.*.*(..))") public void validateLogin(JoinPoint joinPoint) { // check the login information } @Before("validateLogin()") public void validateSession(JoinPoint joinPoint) { // check the session } }
However, this yields org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'projectingArgumentResolverBeanPostProcessor' defined in class path resource [org/springframework/data/web/config/ProjectingArgumentResolverRegistrar.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
.
Deleting the validateSession()
and @Before
makes the @Pointcut
work. How can I fix this?
Advertisement
Answer
The problem is that you define a JoinPoint
parameter in the pointcut. It only belongs in the advice method using the pointcut, not in the pointcut itself. You are not using it there anyway because a pointcut is never executed, the method is just a dummy to be decorated by the @Poinctut
annotation. So what you want is this:
@Pointcut("execution(* show.xianwu.game.frisbeescorer.controller.*.*(..))") public void validateLogin() { // check the login information }
Besides (and unrelated to your problem), the .*.*
is quite specific and only matches a method in a class which is exactly in package show.xianwu.game.frisbeescorer.controller
. If you want to also include classes in subpackages, use the ..
syntax instead, in this case show.xianwu.game.frisbeescorer.controller..*
.