我正在研究使用 Apache-CXF 开发的 REST 服务。我正在使用 Spring 3.1 注释来连接 bean。我编写了一个拦截器,它拦截我的 REST 方法以进行监控。为此,我必须自动装配我的 Monitor 类,该类作为库添加到我的项目中。@Autowired 在这种情况下似乎不起作用并导致 NPE。我在这里做错什么了吗?
@Aspect
@Component
public class ApplicationMonitoring {
Logger logger = LoggerFactory.getLogger(ApplicationMonitoring.class);
@Autowired
private Monitor monitor;
@Around("execution(* com.abc.xyz.rest.CustomerResource.getCustomerByAccountNumber(..))")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
String methodName = joinPoint.getSignature().getName();
long start = System.currentTimeMillis();
try {
// proceed to original method call
Object result = joinPoint.proceed();
monitor.elapsedTime(methodName, System.currentTimeMillis() - start);
return result;
} catch (Exception e) {
throw e;
}
}
应用上下文:
.................
......
<context:spring-configured />
<context:component-scan base-package="com.abc">
<context:exclude-filter expression="org.springframework.stereotype.Controller"
type="annotation" />
</context:component-scan>
<context:annotation-config/>
.............