我从Sonar收到此提示:实例方法不应写入“静态”字段
我不确定要解决此问题需要更改什么.
“ SemaMonitorProxy.applicationContext”是否必须等于静态方法?
public class SemaMonitorProxy implements ApplicationContextAware {
private static ApplicationContext applicationContext = null;
public void registerFailedLoginAttempt(HttpServletRequest request, HttpServletResponse response) {
final SemaMonitor semaMonitor = applicationContext.getBean(SemaMonitor.class);
semaMonitor.registerFailedLoginAttempt(request, response);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
SemaMonitorProxy.applicationContext = applicationContext;
}
}
解决方法:
实际上这种方法:
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
SemaMonitorProxy.applicationContext = applicationContext;
}
是写入静态字段的实例方法:
private static ApplicationContext applicationContext
您不能使上述方法静态.因此,唯一的解决方案是从applicationContext声明中删除static关键字.
private ApplicationContext applicationContext