【问题标题】:Aspectj (ajc) compiler gives error for method parameter pointcutAspectj (ajc) 编译器对方法参数切入点给出错误
【发布时间】:2019-03-26 10:11:26
【问题描述】:

我正在使用 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

【问题讨论】:

    标签: java aspectj pointcut


    【解决方案1】:

    我的错误表达应该是@Before("execution(public * *(.., @ValidateMe (*), ..))")(@ValidateMe 后缺少空格)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多