java - 使用gradle生成方法aspectOf()

标签 java spring-boot gradle aop aspectj

无法使用 gradle 插件生成 aspectOf() 方法。

我的 AspectJ 配置类和一些方面类:

@Aspect
public class SendToAspect {

    @Around("execution (public * *(..)) && @annotation(ann)")
    public Object execute(final ProceedingJoinPoint point, final SendTo ann) throws Throwable {

        return point.proceed();
    }
}

@Configuration
@EnableAspectJAutoProxy
public class AspectjConfiguration {
    @Bean
    public SendToAspect sendToAspect() {
        return Aspects.aspectOf(SendToAspect.class);
    }
}

我的build.gradle:

plugins {
    id 'org.springframework.boot' version '2.2.7.RELEASE'
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
    id "io.freefair.aspectj.base" version "5.1.0"
}

allprojects {
    apply plugin: 'io.spring.dependency-management'
    repositories {
        mavenCentral()
    }
    dependencyManagement {
        dependencies {
            dependency 'org.projectlombok:lombok:1.18.12'
        }
    }
}

subprojects {
    apply plugin: 'java'

    group 'com.example'
    version '0.0.1-snapshot'
    sourceCompatibility = 1.8

    dependencies {
        compileOnly 'org.projectlombok:lombok'
    }
}

configure([project(':my-service')]) {

    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.freefair.aspectj.base'

    dependencies {
        implementation 'org.springframework.boot:spring-boot-starter-web'
        implementation 'org.springframework.boot:spring-boot-starter-aop'
        implementation 'org.springframework.boot:spring-boot-starter-test'
        implementation 'org.springframework:spring-aspects'
        implementation 'org.aspectj:aspectjrt'
   }
}

构建并运行我的 springBoot 应用程序后,我收到相同的错误:

error creating bean with name 'sendToAspect' defined in class path resource
[com/example/config/aspectj/AspectjConfiguration.class]: Bean instantiation via factory method failed;

nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.utils.aop.SendToAspect]:
Factory method 'sendToAspect' threw exception; nested exception is org.aspectj.lang.NoAspectBoundException: 

Exception while initializing com.restaurantclub.soa.utils.aop.SendToAspect: java.lang.NoSuchMethodException: com.restaurantclub.soa.utils.aop.SendToAspect.aspectOf()

需要做什么或我应该使用哪个插件才能工作?

我的 Gradle 版本:5.2.1

最佳答案

解决方案 - 只需使用“io.freefair.aspectj.post-compile-weaving”代替 io.freefair.aspectj.base

关于java - 使用gradle生成方法aspectOf(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62346349/

相关文章:

java - 在 VB.NET 中使用 AesCryptoServiceProvider

Java 正则表达式 : Matching the beginning of a line

java - 使用环境变量 spring boot 在 dynamo db 中动态设置全局二级索引名称

spring-boot - 在类路径中具有 "spring-boot-starter-test"依赖项时无法启动 tomcat 服务器

gradle - Gradle:从现有 war 中删除一些文件对于每个war文件,请执行以下操作:解压,删除/过滤,组合war

java - 将 Struts2 表单保存到数据库

java - Collections.sort - "should implement java.lang.Comparable"

java - Application.yml 值自动转换为小写

Android Studio Gradle - 无法解析依赖项 : acra

android - 更改 Android React-Native 应用程序的上传 key