java - 无法在方法上使用 Aspect
问题描述
这是在一个 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();
}
解决方案
推荐阅读
- javascript - UT010016:不是多部分请求 java servlet
- django - 基于另一个单元格值的引导表单元格
- machine-learning - 我可以在监督机器学习模型中包含交互项作为预测变量之一吗?
- graphics - 着色器无法用于 ThreeJS 升级 - 'viewMartrix: 重新定义
- powershell - 在 ForEach-Object -Parallel 块内从自身递归调用函数 - 在并行块内无法识别函数
- memory - 在 2102 内存芯片上寻址
- vue.js - 对事件总线的性能影响
- javascript - Mongodb 查找所有并更新除一个以外的所有内容
- regex - 重命名文件夹中的所有文件以在 Unix/Mac 上的文件名中包含校验和
- git - 如何在 Android Studio 中使用 Git 命令恢复和删除提交?