aop和注释' selenitance'
让我们考虑以下情况。
@interface LoggedMethodInvocation{}
@LoggedMethodInvocation
@interface MonitoredMethodInvocation{}
我想要@MonitoredMethodInvocation
注释意味着@loggedMethodInvocation
注释。
class LoggingAOPConfig {
@Pointcut("@annotation(LoggedMethodInvocation)")
public void servicePointcut() {
}
@Around("servicePointcut()")
public Object logMethodInvocation(ProceedingJoinPoint pjp) throws Throwable {
// log the method invocation...
}
}
class MonitoringAOPConfig {
@Pointcut("@annotation(MonitoredMethodInvocation)")
public void servicePointcut() {
}
@Around("servicePointcut()")
public Object monitorResponseTime(ProceedingJoinPoint pjp) throws Throwable {
// add some meters to the method invocation
}
}
现在,我想介绍一些方法,这些方法应受到监视和记录。我想仅用一个注释来注释该方法,即@monitoredMethodInvocation
。
class SomeService {
@MonitoredMethodInvocation
Object someMethod(Object requestPayload) {
// ...
return responsePayload;
}
}
但是,它没有播放,记录方面未进入帐户。
有Spring的AnnotationUtils.findannotation
提供所需的功能(识别,是否应考虑@LoggedMethodInvocation
)。但是,我不知道如何将其放入点尺寸配置中。
我应该如何修改日志记录AOP配置,以便它可以识别日志记录注释,即使它隐藏在@MonitoredMethodInvocation
后面?
let's consider the following situation.
@interface LoggedMethodInvocation{}
@LoggedMethodInvocation
@interface MonitoredMethodInvocation{}
I would like the @MonitoredMethodInvocation
annotation implying the @LoggedMethodInvocation
annotation.
class LoggingAOPConfig {
@Pointcut("@annotation(LoggedMethodInvocation)")
public void servicePointcut() {
}
@Around("servicePointcut()")
public Object logMethodInvocation(ProceedingJoinPoint pjp) throws Throwable {
// log the method invocation...
}
}
class MonitoringAOPConfig {
@Pointcut("@annotation(MonitoredMethodInvocation)")
public void servicePointcut() {
}
@Around("servicePointcut()")
public Object monitorResponseTime(ProceedingJoinPoint pjp) throws Throwable {
// add some meters to the method invocation
}
}
Now I would like to introduce some method, which shall be both monitored and logged. And I would like to annotate the method only with one annotation, namely @MonitoredMethodInvocation
.
class SomeService {
@MonitoredMethodInvocation
Object someMethod(Object requestPayload) {
// ...
return responsePayload;
}
}
However it doesn't play, the logging aspect is not taken into the account.
There is spring's AnnotationUtils.findAnnotation
which offers the needed functionality (of recognizing, whether the @LoggedMethodInvocation
shall be considered). However, I don't know how to put this into the pointcut configuration.
How shall I modify the logging AOP config so it will recognize the logging annotation even if it is hidden behind the @MonitoredMethodInvocation
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用来自 https://stackoverflow.com/a/a/38209801/3394495 的语法。
Using the syntax from https://stackoverflow.com/a/38209801/3394495, this should work for your case: