Springboot 创建bean

package com.wbb.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
* @author wangbinbin
* @create 2021-07-02
*/
@Configuration//代表这是一个springboot配置类。类似Spring.xml文件。
public class BeansConfig {


//交由工厂创建对象。启动就创建
@Bean
public RestTemplate getRestTemplate(){
return new RestTemplate();
}
}


以后想使用这个bean 只需要使用 @Autowired 注解 注入就行
posted @ 2021-07-02 20:33  neoQVQ  阅读(344)  评论(0)    收藏  举报