用gradle生成方法 aspectOf()

问题描述 投票:0回答:1

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

我的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.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 5.2.1

java spring-boot gradle aop aspectj
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.