我正在使用Aspectj编译时编织技术,并且试图为那些对任何参数应用了注释的方法应用建议。
我要向谁提出建议的方法
public void link(String departmentId, @ValidateMe(validatorClass = EmployeeValidator.class) Set<Employee> employees, SystemMessageContext messageContext) {
}
我的注释
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface ValidateMe {
Class<? extends Validator> validatorClass();
}
我的建议
@Aspect
public class ValidationAdvice {
private static final Logger LOGGER = LoggerFactory.getLogger(ValidationAdvice.class);
@Before("execution(public * *(.., @ValidateMe(*), ..))")
public void validateMe(JoinPoint joinPoint) {
}
我的pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<proc>none</proc>
<complianceLevel>1.8</complianceLevel>
<showWeaveInfo>true</showWeaveInfo>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.13</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.13</version>
</dependency>
</dependencies>
</plugin>
它将给我编译错误Error:(24, 0) ajc: Syntax error on token "execution(public * *(.., @ValidateMe(*), ..))", "name pattern" expected
答案 0 :(得分:0)
我的错误表达应该是@Before("execution(public * *(.., @ValidateMe (*), ..))")
(@ ValidateMe之后缺少空格)。