sonar代码检查Make the enclosing method static or remove this set.

sonar检查不通过位置

public class SpringContextHolder implements ApplicationContextAware {

	private static ApplicationContext applicationContext;
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		SpringContextHolder.applicationContext = applicationContext;
		//Make the enclosing method "static" or remove this set.
	}
}

解决方法

创建一个常量类

public class Constant {

	public static ApplicationContext applicationContext;
	
}
public class SpringContextHolder implements ApplicationContextAware {

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		Constant.applicationContext = applicationContext;
	}
	
}

你可能感兴趣的:(Java)