首页 > 编程语言 > 详细

Springboot 创建bean

时间:2021-07-02 23:03:53      阅读:34      评论:0      收藏:0      [点我收藏+]
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 注解 注入就行

Springboot 创建bean

原文:https://www.cnblogs.com/binstudy/p/14964811.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!