我使用spring AOP来记录使用@RequestMapping定义的端点的整个事务和子事务的执行时间。
我的端点定义如下:
package com.example.service
@RestController
public class endpoints {
@Autowired
SomeObject object;
@RequestMapping(value = "/123", method = { RequestMethod.GET })
public void test() {
object.doSomething();
}
}
我的示例对象
package com.example.objects
@Repository
public class SomeObject {
public void doSomething() {
System.out.println("doing something");
}
}
记录方面:
@Component
@Aspect
public class LoggingAspect {
// THIS WORKS
@Around(value = "within(com.example.service ..*) && @annotation(mapping) ")
public Object logEndpoint(ProceedingJoinPoint joinPoint, RequestMapping mapping) throws Throwable {
System.out.println("Endpoint works!!");
}
// THIS DOES NOT WORK
@Around("execution(* com.example.objects.SomeObject.doSomething(..))")
public void specificMethod(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("LOGGING FOR REALS YA'LL");
joinPoint.proceed();
}
}
当我部署它并且我点击端点applicationName / 123时,日志记录对端点起作用。问题是我没有得到“doSomething()”的日志记录。我认为自动装配会创建适当的代理,我需要该方面才能工作,但显然它没有。我怎样才能恰当地调用我的方法“doSomething()”来让它与方面一起记录?