springboot中static代码块中获取yml中配置
@Configuration
public class OpencvConfig {
private static String pathStr;
@Value("${opencv.path}")
public void setWinPathStr(String path) {
pathStr = path;
}
public String getPathStr() {
return pathStr;
}
}
@Slf4j @Component @AutoConfigureAfter(OpencvConfig.class) public class DisclosureCrawl { @Autowired private IBusBillWarnitemService billWarnitemService; @Autowired private IBusBillWarnService billWarnService; private CloseableHttpClient httpclient = null; private CloseableHttpResponse response = null; static { OpencvConfig oc = new OpencvConfig(); String os = System.getProperty("os.name"); if (os != null && os.toLowerCase().startsWith("windows")) { //Windows操作系统 System.load(oc.getPathStr()); } else if (os != null && os.toLowerCase().startsWith("linux")) { //Linux操作系统 log.info(String.format("当前系统版本是:%s", os)); } else { //其它操作系统 log.info(String.format("当前系统版本是:%s", os)); } }