2020-09-10 14:47:58.735 [main][] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'abilityPlatformService': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: ClientHttpRequestFactory must not be null
怀疑:

private ClientHttpRequestFactory factory;
private RestTemplate restTemplate;

@Autowired
public void setFactory() {
    SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
    factory.setConnectTimeout(30000);// ms
    factory.setReadTimeout(30000);// ms

// this.factory = factory;

}

@Autowired
public void setRestTemplate() {
    this.restTemplate = new RestTemplate(this.factory);
}

就是!
ClientHttpRequestFactory要做成一个@Bean。否则在idea和linux上可以,docker不行。

2020-09-10 15:44:26.528 [main][] WARN org.apache.catalina.loader.WebappClassLoaderBase - The web application [ROOT] appears to have
started a thread named [Druid-ConnectionPool-Destroy-2111019038] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Thread.sleep(Native Method)
com.alibaba.druid.pool.DruidDataSource$DestroyConnectionThread.run(DruidDataSource.java:2172)
这个不用管,解决了上面的 BeanCreationException 就没有了。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'abilityPlatformService': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: ClientHttpRequestFactory must not be null
// this.factory = factory;
注释掉就是这个错。

@Autowired
private ClientHttpRequestFactory factory;
报错:

Could not autowire. There is more than one bean of 'ClientHttpRequestFactory' type.
Beans:
clientHttpRequestFactory   (ClientHttpRequestFactoryConfig.java) ribbonClientHttpRequestFactory   (RibbonAutoConfiguration.class)
more... (⌘F1)
解决
@Primary

解决了!
估计:
@Autowired的顺序是无法保证的。
但@Bean、@Service这种spring会通过循环依赖来解决。

@autowired注入顺序:构造方法->属性->set方法。所以在构造方法中直接使用属性的值会报NPE。
https://blog.csdn.net/lllllll... spring @autowired注入顺序

2.@Autowired方法的注入顺序依赖于class.getDeclaredMethods()的顺序
https://blog.csdn.net/chokee/...

评论
载入中...