要在spring中使用jamon,described需要使用JamonPerformanceMonitorInterceptor,并通过applicationContext.xml将其放入springs机制中。这已经解释过了,在tests in it's sources中有一个例子。不幸的是,我想构建一个没有任何xml配置的spring-boot应用程序。
是否可以使用一些注释来包含spring的JamonPerformanceMonitorInterceptor?
发布于 2016-02-02 06:49:53
迟到总比不到好。
我遇到了完全相同的情况:我需要在没有任何JAMon配置的情况下配置XML。大多数在线示例(包括JAMon源代码中的注释)都在宣传XML配置的灵活性,但我找不到任何基于注释的配置示例。另外,基于注解的配置不一定不灵活,它们只需要在概念上分开,并且不能与应用程序的功能部分混淆。我认为这样的顾问可以是一个很好的例子:
@Component
public class MonitoringAdvisor extends AbstractPointcutAdvisor {
private final StaticMethodMatcherPointcut pointcut = new StaticMethodMatcherPointcut() {
@Override
public boolean matches(Method method, Class<?> targetClass) {
return targetClass.isAnnotationPresent(RestController.class);
}
};
@Override
public Pointcut getPointcut() {
return this.pointcut;
}
@Override
public Advice getAdvice() {
return new JamonPerformanceMonitorInterceptor(true, true);
}
}这个顾问将让Spring/AOP知道在任何带有@RestContrller注释的Spring bean方法上运行JAMon监控建议。这个advisor应该配置/添加到与rest控制器相同的Spring上下文中。
注意,在我的例子中,我特别想监控我的rest控制器。您可以根据自己的需要调整advisor。(在我的代码中,我使用了一个更高级/可配置的advisor版本)
发布于 2015-01-21 21:13:13
这个Spring Boot sample application有帮助吗?
以下是Spring AOP manual的相关部分。
https://stackoverflow.com/questions/28056736
复制相似问题