借鉴和参考了:http://blog.csdn.net/ohalo/article/details/48999863
错误写法:
@Autowired private static OpenSearchProperties openSearchProperties;
这个写法报错:Autowired annotation is not supported on static fields
解决方案一:就是不用static (如果你非要用,请看解决方案二)
解决方案二:
扫描二维码关注公众号,回复:
253168 查看本文章
private static OpenSearchProperties openSearchProperties; @Resource(name = "openSearchProperties") public void setOpenSearchProperties(OpenSearchProperties openSearchProperties) { OpenSearchUtil.openSearchProperties = openSearchProperties; }
其中 @Resource(name = "openSearchProperties") 中的openSearchProperties 就是你要导入的 serice、dao、Component、Configuration等 spring 依赖注入的类