简体   繁体   English

春豆工厂模型

[英]Spring Beans Factory Model

/* Can You please help me? /* 你能帮我么? I have just started Spring. 我刚刚开始春季。

I know about Singleton and prototype but there is third one also . 我知道Singleton和原型,但也有第三种。 The third is Factory model . 第三是工厂模式。
The sample code is: 示例代码是:

        */
             package com.springinaction.springidol;
            public classStage{
            private Stage(){
            }
            private static classStageSingletonHolder{
            staticStageinstance=newStage();
            }
            public staticStagegetInstance(){
            returnStageSingletonHolder.instance;
            }
            }
   /*         
       // XML is 

            <bean id="theStage"
        class="com.springinaction.springidol.Stage"
        factory-method="getInstance" />

*/

What is different between Factory model and singleton and prototype. Factory模型与单例和原型之间有什么不同。 And when I will use factory model and why? 何时使用工厂模型,为什么?

There is two type of factory method in Spring.Read the details in link given below Spring有两种类型的工厂方法,请阅读下面给出的链接中的详细信息

  1. Static factory method 静态工厂方法

  2. Instance factory method 实例工厂方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM