Springboot @Autowired @Resource does not support static variables solution

For reference and reference: http://blog.csdn.net/ohalo/article/details/48999863

 

Wrong spelling:

 

@Autowired
private static OpenSearchProperties openSearchProperties;

 This writing error: Autowired annotation is not supported on static fields

 

 

Solution 1: Just don't use static (if you have to use it, please see solution 2)

 

Solution two:

 

 

private static OpenSearchProperties openSearchProperties;
@Resource(name = "openSearchProperties")
    public void setOpenSearchProperties(OpenSearchProperties openSearchProperties) {
        OpenSearchUtil.openSearchProperties = openSearchProperties;
    }

 Among them, openSearchProperties in @Resource(name = "openSearchProperties") is the spring dependency injection class such as serice, dao, Component, Configuration, etc. that you want to import

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326487150&siteId=291194637