星空网 > 软件开发 > Java

Spring 通过FactoryBean配置Bean

1.实现FactoryBean接口

import org.springframework.beans.factory.FactoryBean;

public class CarFactoryBean implements FactoryBean<Car> {

 @Override
 public Car getObject() throws Exception {
  // TODO Auto-generated method stub
  return new Car("Qq",100);
 }

 @Override
 public Class<?> getObjectType() {
  return Car.class;
 }

 @Override
 public boolean isSingleton() {
  // TODO Auto-generated method stub
  return true;
 }

}

2.配置FactoryBean  工厂 Bean 跟普通Bean不同, 其返回的对象不是指定类的一个实例, 其返回的是该工厂 Bean 的 getObject 方法所返回的对象。

<bean id="car" ></bean> 配置的是FactoryBean的实例,但是返回的是FactoryBean的 getObject 方法所返回的对象。




原标题:Spring 通过FactoryBean配置Bean

关键词:Spring

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

未来零售策略解密:品牌全球化与新兴零售模式的交汇:https://www.kjdsnews.com/a/1726953.html
新店运营指南第十五期 - 纠纷处罚与申诉:https://www.kjdsnews.com/a/1726954.html
跨境卖家红利期要来了!这些因素很重要!:https://www.kjdsnews.com/a/1726955.html
亚马逊卖家容易忽略的促销流量入口,还有特殊的专属标识:https://www.kjdsnews.com/a/1726956.html
37号文个人境外投资备案多久?解析时间限制与申报流程:https://www.kjdsnews.com/a/1726957.html
美国市场依旧吃香!卖家如何把握2024年暴富机会?:https://www.kjdsnews.com/a/1726958.html
皇帝的皇宫=:https://www.vstour.cn/a/363188.html
海南岛琼海市旅游景点 琼海市的旅游景点:https://www.vstour.cn/a/363189.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流