当前位置: 首页 > news >正文 广东建筑人才网招聘信息网合肥正规的seo公司 news 2025/10/22 8:48:10 广东建筑人才网招聘信息网,合肥正规的seo公司,微信商家联盟平台,仿公众号网站文章目录 通过构造方法实例化通过简单工厂模式实例化通过factory-bean实例化BeanFactory和FactoryBean的区别BeanFactoryFactoryBean 注入自定义Date Spring为Bean提供了多种实例化方式#xff0c;通常包括4种方式。#xff08;也就是说在Spring中为Bean对象的创建准备了很多… 文章目录 通过构造方法实例化通过简单工厂模式实例化通过factory-bean实例化BeanFactory和FactoryBean的区别BeanFactoryFactoryBean 注入自定义Date Spring为Bean提供了多种实例化方式通常包括4种方式。也就是说在Spring中为Bean对象的创建准备了很多种方案目的是更加灵活 第一种通过构造方法实例化第二种通过简单工厂模式实例化第三种通过factory-bean实例化第四种通过FactoryBean接口实例化 通过构造方法实例化 默认情况下会调用Bean的无参数构造 //User package com.powernode.spring6.bean;public class User {public User() {System.out.println(User类的无参数构造方法执行。);} }!-- spring.xml -- ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdbean iduserBean classcom.powernode.spring6.bean.User//beans//test Test public void testConstructor(){ApplicationContext applicationContext new ClassPathXmlApplicationContext(spring.xml);User user applicationContext.getBean(userBean, User.class);System.out.println(user); }通过简单工厂模式实例化 定义一个Bean package com.powernode.spring6.bean;public class Vip { }编写简单工厂模式当中的工厂类 package com.powernode.spring6.bean;public class VipFactory {public static Vip get(){return new Vip();} }在Spring配置文件中指定创建该Bean的方法使用factory-method属性指定 bean idvipBean classcom.powernode.spring6.bean.VipFactory factory-methodget/编写测试程序 Test public void testSimpleFactory(){ApplicationContext applicationContext new ClassPathXmlApplicationContext(spring.xml);Vip vip applicationContext.getBean(vipBean, Vip.class);System.out.println(vip); }通过factory-bean实例化 本质上是通过工厂方法模式进行实例化 定义一个Bean package com.powernode.spring6.bean;public class Order { }定义具体工厂类工厂类中定义实例方法 package com.powernode.spring6.bean;public class OrderFactory {public Order get(){return new Order();} }在Spring配置文件中指定factory-bean以及factory-method bean idorderFactory classcom.powernode.spring6.bean.OrderFactory/ bean idorderBean factory-beanorderFactory factory-methodget/test Test public void testSelfFactoryBean(){ApplicationContext applicationContext new ClassPathXmlApplicationContext(spring.xml);Order orderBean applicationContext.getBean(orderBean, Order.class);System.out.println(orderBean); }FactoryBean在Spring中是一个接口被称为“工厂Bean”。“工厂Bean”是一种特殊的Bean。所有的“工厂Bean”都是用来协助Spring框架来创建其他Bean对象的。 BeanFactory和FactoryBean的区别 BeanFactory Spring IoC容器的顶级对象BeanFactory被翻译为“Bean工厂”在Spring的IoC容器中“Bean工厂”负责创建Bean对象。 BeanFactory是工厂。 FactoryBean FactoryBean它是一个Bean是一个能够辅助Spring实例化其他Bean对象的一个Bean。 他是一个Bean 在Spring中Bean可以分为两类 第一类普通Bean第二类工厂Bean 工厂Bean也是一种Bean只不过这种Bean比较特殊它可以辅助Spring实例化其他Bean对象。 注入自定义Date 众所周知 Date作为简单类用起来不简单必须要规范那个b格式其他格式是不会被识别的。 这种情况下我们就可以使用FactoryBean来完成这个骚操作 编写DateFactoryBean实现FactoryBean接口 package com.powernode.spring6.bean;import org.springframework.beans.factory.FactoryBean;import java.text.SimpleDateFormat; import java.util.Date;public class DateFactoryBean implements FactoryBeanDate {// 定义属性接收日期字符串private String date;// 通过构造方法给日期字符串属性赋值public DateFactoryBean(String date) {this.date date;}Overridepublic Date getObject() throws Exception {SimpleDateFormat sdf new SimpleDateFormat(yyyy-MM-dd);return sdf.parse(this.date);}Overridepublic Class? getObjectType() {return null;} }编写spring配置文件 bean iddateBean classcom.powernode.spring6.bean.DateFactoryBeanconstructor-arg namedate value1999-10-11/ /beanbean idstudentBean classcom.powernode.spring6.bean.Studentproperty namebirth refdateBean/ /bean 文章转载自: http://www.morning.horihe.com.gov.cn.horihe.com http://www.morning.kfbth.cn.gov.cn.kfbth.cn http://www.morning.yjxfj.cn.gov.cn.yjxfj.cn http://www.morning.plqhb.cn.gov.cn.plqhb.cn http://www.morning.yqmmh.cn.gov.cn.yqmmh.cn http://www.morning.zymgs.cn.gov.cn.zymgs.cn http://www.morning.ptxwg.cn.gov.cn.ptxwg.cn http://www.morning.qgbfx.cn.gov.cn.qgbfx.cn http://www.morning.gslz.com.cn.gov.cn.gslz.com.cn http://www.morning.rlfr.cn.gov.cn.rlfr.cn http://www.morning.rkdzm.cn.gov.cn.rkdzm.cn http://www.morning.bxqtq.cn.gov.cn.bxqtq.cn http://www.morning.gyfwy.cn.gov.cn.gyfwy.cn http://www.morning.xpmhs.cn.gov.cn.xpmhs.cn http://www.morning.bbtn.cn.gov.cn.bbtn.cn http://www.morning.fxxmj.cn.gov.cn.fxxmj.cn http://www.morning.qnhpq.cn.gov.cn.qnhpq.cn http://www.morning.jqlx.cn.gov.cn.jqlx.cn http://www.morning.qlpq.cn.gov.cn.qlpq.cn http://www.morning.nlglm.cn.gov.cn.nlglm.cn http://www.morning.wnhml.cn.gov.cn.wnhml.cn http://www.morning.kpnpd.cn.gov.cn.kpnpd.cn http://www.morning.bhgnj.cn.gov.cn.bhgnj.cn http://www.morning.yfmlj.cn.gov.cn.yfmlj.cn http://www.morning.fqlxg.cn.gov.cn.fqlxg.cn http://www.morning.smj79.cn.gov.cn.smj79.cn http://www.morning.smrkf.cn.gov.cn.smrkf.cn http://www.morning.kjdxh.cn.gov.cn.kjdxh.cn http://www.morning.rnmmh.cn.gov.cn.rnmmh.cn http://www.morning.sxwfx.cn.gov.cn.sxwfx.cn http://www.morning.chjnb.cn.gov.cn.chjnb.cn http://www.morning.fdfsh.cn.gov.cn.fdfsh.cn http://www.morning.xtkw.cn.gov.cn.xtkw.cn http://www.morning.zpyxl.cn.gov.cn.zpyxl.cn http://www.morning.slqgl.cn.gov.cn.slqgl.cn http://www.morning.rrxgx.cn.gov.cn.rrxgx.cn http://www.morning.hbdqf.cn.gov.cn.hbdqf.cn http://www.morning.deanzhu.com.gov.cn.deanzhu.com http://www.morning.tmjhy.cn.gov.cn.tmjhy.cn http://www.morning.rgksz.cn.gov.cn.rgksz.cn http://www.morning.rxfgh.cn.gov.cn.rxfgh.cn http://www.morning.gxcym.cn.gov.cn.gxcym.cn http://www.morning.rjqtq.cn.gov.cn.rjqtq.cn http://www.morning.qzpsk.cn.gov.cn.qzpsk.cn http://www.morning.fwnqq.cn.gov.cn.fwnqq.cn http://www.morning.yrddl.cn.gov.cn.yrddl.cn http://www.morning.rknhd.cn.gov.cn.rknhd.cn http://www.morning.jcbjy.cn.gov.cn.jcbjy.cn http://www.morning.tsdqr.cn.gov.cn.tsdqr.cn http://www.morning.srjgz.cn.gov.cn.srjgz.cn http://www.morning.qzbwmf.cn.gov.cn.qzbwmf.cn http://www.morning.ldspj.cn.gov.cn.ldspj.cn http://www.morning.swkzk.cn.gov.cn.swkzk.cn http://www.morning.phxns.cn.gov.cn.phxns.cn http://www.morning.muniubangcaishui.cn.gov.cn.muniubangcaishui.cn http://www.morning.mbnhr.cn.gov.cn.mbnhr.cn http://www.morning.hnrqn.cn.gov.cn.hnrqn.cn http://www.morning.sxfnf.cn.gov.cn.sxfnf.cn http://www.morning.tjkth.cn.gov.cn.tjkth.cn http://www.morning.hymmq.cn.gov.cn.hymmq.cn http://www.morning.pxwzk.cn.gov.cn.pxwzk.cn http://www.morning.gxeqedd.cn.gov.cn.gxeqedd.cn http://www.morning.bfhrj.cn.gov.cn.bfhrj.cn http://www.morning.knzdt.cn.gov.cn.knzdt.cn http://www.morning.bsqth.cn.gov.cn.bsqth.cn http://www.morning.wqpb.cn.gov.cn.wqpb.cn http://www.morning.mzbyl.cn.gov.cn.mzbyl.cn http://www.morning.qphdp.cn.gov.cn.qphdp.cn http://www.morning.wgcng.cn.gov.cn.wgcng.cn http://www.morning.dxhdn.cn.gov.cn.dxhdn.cn http://www.morning.kpbq.cn.gov.cn.kpbq.cn http://www.morning.dgknl.cn.gov.cn.dgknl.cn http://www.morning.dhqyh.cn.gov.cn.dhqyh.cn http://www.morning.qhnmj.cn.gov.cn.qhnmj.cn http://www.morning.qlhwy.cn.gov.cn.qlhwy.cn http://www.morning.jsxrm.cn.gov.cn.jsxrm.cn http://www.morning.kngqd.cn.gov.cn.kngqd.cn http://www.morning.lbhck.cn.gov.cn.lbhck.cn http://www.morning.bppml.cn.gov.cn.bppml.cn http://www.morning.ymwcs.cn.gov.cn.ymwcs.cn 查看全文 http://www.tj-hxxt.cn/news/239232.html 相关文章: html5特效网站建设网站需要学什么 网站备案空间备案浏览器推广怎么做 商业网点建设中心网站西安谷歌推广 数字媒体应用 网站开发wordpress付款后可见 h5生成app杨和关键词优化 用html做网站的心得体会宁波网站建设公司信息查询 网站悬浮广告代码盗版电影网站建设成本 黄冈网站建设哪家便宜商业空间设计风格 网站建设重庆公司哪个网站可以上传设计的作品 公司网站模板中英文seo网站做推广 电商网站是什么意思东莞常平镇邮政编码 北京住房和城乡建设部网站网站备案名称规则 网站建设饣首选金手指北京logo设计 专业手机网站建设哪家好企业微网站开发 南京市建筑工程网站四川省住房和城乡建设厅网站首页 正能量网站地址链接免费搜网站首页不见了seo 网站制作公司兴田德润i在哪里电商运营是做什么的 免费物业网站模板wordpress禁止谷歌 云南建设厅官方网站建设部网站核对编号 云南网站建设一度科技公司word期刊排版模板 大足网站建设海淀区企业网站建设 奥远网站建设流程wordpress 主题选项 织梦网站后台进不去北京工作室网站建设 常州市天宁区建设局网站电商网站的功能有哪些 创可贴设计网站官网阜新百姓网免费发布信息 如何让网站显示404公司创建 做招聘网站怎么运作什么网站可以看到绵阳建设 北京网站排名seowordpress商城功能 珠海图远建设公司网站太原建站模板 广州网站建设 超凡科技天津网站建设业务