做SpringBoot项目,为何有的时候需要写配置类
@Configuration+@Bean产生一个类的对象交给Spring管理
然后@Resource注入
比如RestTemplate
如果不写配置类Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your configuration.
但有的时候不需要些配置类
比如
@Resource
private DiscoveryClient discoveryClient;
请问什么时候用类可以直接注入,什么时候需要自己写配置类