当前位置: 首页 > news >正文

做系统网站建设无锡百姓网推广

做系统网站建设,无锡百姓网推广,wordpress会员积分,上海商贸公司企业查询1.首先说说 factory-method 是指定创造实例的工厂方法,用法: factory-method 和 class 配合使用,这时 factory-method 必须是class所指定的类中的一个静态方法,也就是Spring会直接调用 class 所指定的类的静态工厂方法创建一个实例…

1.首先说说 factory-method 是指定创造实例的工厂方法,用法:

        factory-method 和 class 配合使用,这时 factory-method 必须是class所指定的类中的一个静态方法,也就是Spring会直接调用 class 所指定的类的静态工厂方法创建一个实例,然后注册到IOC 容器中

        factory-method 和 factory-bean 配合使用,factory-bean必须是IOC容器中存在的一个bean实例  beanA,factory-method 配置 factory-bean 所指定的实例 beanA 的一个工厂方法,也就是Spring会先创建 factory-bean 所指定的这个实例 beanA,然后调用beanA的工厂方法,创建一个新的实例 beanB,然后注册到IOC 容器中

以上描述可以看出 

        1.factory-bean 这个属性和 接口 FactoryBean 没有关系

        2.factory-method 必须要和 class 或者 factory-bean 中的一个配合使用,如果class 和 factory-bean都配置了,那么class就不起作用了

factory-bean的官方说明:
Alternative to class attribute for factory-method usage.If this is specified, no class attribute should be used.This must be set to the name of a bean in the current or
ancestor factories that contains the relevant factory method.This allows the factory itself to be configured using Dependency Injection, and an instance (rather than static) method to be used.
翻译:使用factory-method时,class属性的替代方案,如果指定了这个(factory-bean),class属性就不用了。factory-bean必须设置一个在当前容器或者父容器中存在的bean,并且这个bean必须拥有factory-method所指定的工厂方法。这种配置方式容许这个工厂bean通过依赖注入进行配置,factory-method 配置的是一个实例方法,不是静态方法
<bean id="exampleFactory" class="com.example.ExampleFactory"><!-- Inject dependencies here -->
</bean><bean id="exampleBean" factory-bean="exampleFactory" factory-method="createInstance"/>
factory-method的官方说明:
The name of a factory method to use to create this object. Use constructor-arg elements to specify arguments to the factory method,if it takes arguments. Autowiring does not apply to factory methods.
创建这个对象的工厂方法的方法名,如果工厂方法需要参数,就用constructor-arg标签来给工厂方法指定参数。自动注入不会被应用到工厂方法。If the "class" attribute is present, the factory method will be a static method on the class specified by the "class" attribute on this bean definition. Often this will be the same class as that of the constructed object - for example, when the factory method is used as an alternative to a constructor. However, it may be on a different class. In that case, the created object will *not* be of the class specified in the "class" attribute. This is analogous to FactoryBean behavior.
如果配置了class属性,factory-method必须得是这个bean definition的class属性指定的类中的一个静态方法,通常这个class属性指定的类和工厂方法创建的对象所属的类是相同的,举例:当factory method被当作constructor的替代方案来创造对象时,这个factory method可能属于一个不同的类。这种情况下factory method创造的对象就不是class属性所指定的类的实例。这有点类似FactoryBean的用法。If the "factory-bean" attribute is present, the "class" attribute is not used, and the factory method will be an instance method on the object returned from a getBean call with the specified bean name. The factory bean may be defined as a singleton or a prototype.
如果指定了factory-bean这个属性,class属性就不会启用了,factory-method必须是,用factory-bean属性作为参数,调用getBean返回的实例对象的一个实例方法(必须是 getBean(factory-bean)的一个实例方法  )。factory-bean 可以是单例模式,也可以是原型模式The factory method can have any number of arguments. Autowiring is not supported. Use indexed constructor-arg elements in conjunction with the factory-method attribute.
factory-method 可以有任意个数的参数,不支持工厂方法自动注入。把排好顺序的constructor-arg和factory-method结合使用。Setter Injection can be used in conjunction with a factory method.Method Injection cannot, as the factory method returns an instance,which will be used when the container creates the bean.
set方法注入可以和工厂方法联合使用,方法注入不可以和工厂方法不可以联合使用,因为当容器需要创造bean的时候,工厂方法返回一个实例。

        

http://www.ritt.cn/news/29086.html

相关文章:

  • 郑州新闻头条最新消息搜索引擎优化的五个方面
  • 用固定ip做访问网站服务器外贸google推广
  • 信息产业部网站备案系统百度搜索热词排行榜
  • 网站网页设计设计方案网络营销的含义特点
  • 主流建站开源程序有哪些苏州网站关键词优化推广
  • 深圳城乡和住房建设局网站首页如何做好线上推广和引流
  • 做网站自适应框架百度seo关键词排名优化工具
  • 潍坊哪里有做360网站的seo是哪个英文的简写
  • 中国建设银行门户网站南宁整合推广公司
  • 网络工程师免费教程宁波seo外包
  • 企业信息系统的架构seo如何提高排名
  • 做网站跟做app哪个累石家庄seo关键词
  • 企业网站开发公司排名引擎搜索优化
  • 如何写代码做网站6seo公司后付费
  • wordpress小工具 样式广州百度搜索排名优化
  • 邵阳网站建设上海seo博客
  • 长春做网站外包久久seo正规吗
  • 专注网站开发三亚百度推广地址
  • 网站开发的工作内容seo还有未来吗
  • 做网站用到的java技术搜索引擎优化的定义
  • wordpress主题后台管理seo优化内容
  • 学做游戏 网站网站设计说明
  • 珠海专业医疗网站建设球队排名榜实时排名
  • 企业网站用vps还是虚拟主机网络促销的方法有哪些
  • 谷歌镜像网站怎么做网站推广网
  • php软件安装广西seo快速排名
  • 当牛做吗网站源代码分享优化关键词排名公司
  • 简网app工场官网网址seo门户网站建设方案
  • ps网站设计概述东莞seo托管
  • pt网站怎么下载与做批量查询指数