无法通过一种方法使用Aspect

时间:2019-06-20 15:33:14

标签: java spring aop aspectj

这是在Spring项目中,我在另一个模块所依赖的不同模块中设置了Aspect。我正在使用自定义注释。它在某些方法上工作正常,而在另一些方法上则无效。我可以就问题出在哪里寻求建议吗?

此Aspect类来自一个模块,其他模块都依赖于此。

@Aspect
@Component
public class VirtualizeJsonAspect {
    @Around("@annotation(virtualizeJson)")
    public Object virtualizeJsonAround(ProceedingJoinPoint pjp, VirtualizeJson virtualizeJson) throws Throwable {
        MethodSignature signature = (MethodSignature) pjp.getSignature();
        Method method = signature.getMethod();
        Class returnType = signature.getReturnType();
    // ....... This is working fine
}

在同一个模块中有3个类(如果相关)

当我尝试使用Aspect时,它在这里起作用

参考路径-> com / domain / abc / service / helper / DataHelper.java

@Component
@PropertySource("classpath:something.properties")
public class DataHelper {

    @VirtualizeJson(serviceNm = "ABC", virtualizedDataPath = "/url/some.json")
    public SomeResponse getOffers(SomeRequest someRequest){

        HttpEntity httpRequestEntity = createRequestEntity(request);

        ResponseEntity<SomeResponse> httpResponseEntity;
        SomeResponse someResponse = null;
        // ......... Aspect works here. I do not get in here. Instead I land in the Aspect class as expected
    }
}

配置文件 参考路径-> com / domain / abc / service / config / AppConfig.java

@Configuration
@ComponentScan(basePackages = {{"com.domain.virtualize"})
@EnableAspectJAutoProxy
public class AppConfig extends WebMvcConfigurationSupport{
    // some bean setups not rlevant to Aspect
}

当我尝试使用Aspect时,它在这里不起作用

参考路径-> com / domain / abc / service / rules / CheckSomething.java

@Component
public class CheckSomething extends SomeRule {

    @VirtualizeJson(serviceNm = "ABC", virtualizedDataPath = "/url/some.json")
    public SomeResponse checkOffers(String someNumber){

        int a = 1;
        return null;
        // I land inside this method which is incorrect. I shouldh have landed at the Aspect class instead 
    }
}

注释

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface VirtualizeJson {
    public String serviceNm();
    public String virtualizedDataPath();
}

0 个答案:

没有答案