码是什么,我的问题是关于:CommandLineRunner和豆类(春季)
@SpringBootApplication
public class Application {
private static final Logger log = LoggerFactory.getLogger(Application.class);
public static void main(String args[]) {
SpringApplication.run(Application.class);
}
@Bean
public Object test(RestTemplate restTemplate) {
Quote quote = restTemplate.getForObject(
"http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
log.info(quote.toString());
return new Random();
}
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build();
}
@Bean
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
return args -> {
Quote quote = restTemplate.getForObject(
"http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
log.info(quote.toString());
};
}
}
我很新的春天。据我了解,@Bean注释是负责将对象保存在IoC容器中,请纠正?
如果是这样的话:首先收集@Bean的所有方法并执行然后执行?
在我的例子,我添加的方法测试()是什么一样的run(),但返回的对象(随机())来代替。 结果与使用CommandLineRunner和Object时相同。
是否有一个原因,它应该返回CommandLineRunner即使用像奔跑的语法()?
此外:在这一点上我没有看到,到目前为止,移动的方法来一个集装箱的优势。为什么不直接执行它?
谢谢!