【发布时间】:2018-02-09 16:28:44
【问题描述】:
我有一个用例,我想拦截使用我的自定义注释进行注释的 Spring 控制器函数。让我们将我的注释称为@CustomerAnnotation。
我有一个控制器 MyController
public class MyController extends Controller {
@CustomerAnnotation
@RequestMappint("/test")
public void test() {
// SOME CODE
}
我的 AspectJ 类:
@Aspect
@Component
public class CustomImpl implements CustomAspect {
@Around("@annotation(CustomerAnnotation)")
@Override
public Object testAnnotation(ProceedingJoinPoint proceedingJoinPoint) {
System.out.println("Inside annotaion");
try {
Object returnObj = proceedingJoinPoint.proceed();
return returnObj;
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
};
}
每当我调用我的 API 时,我都会收到以下异常:
The mapped controller method class 'com.controller.MyController' is not an instance of the actual controller bean instance 'com.sun.proxy.$Proxy154'. If the controller requires proxying (e.g. due to @Transactional), please use class-based proxying.
HandlerMethod details:
我的 CustomerAnnotation 类:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface CustomerAnnotation {
}
有什么解决办法吗?
我尝试在我的服务功能上使用相同的逻辑,并且它在那里工作。
更新:当我添加 @EnableAspectJAutoProxy(proxyTargetClass = true) 时,它会给出以下异常
Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class
请帮忙
【问题讨论】:
-
请出示您的@CustomerAnnotation 代码。
-
@ViníciusCarneirodeBrito 完成
-
你在使用任何xml映射文件吗??
-
@Nithin xml 映射什么?
-
显示您的 AspectJ 配置。
标签: java spring spring-mvc aop aspectj