美文网首页
Spring创建对象

Spring创建对象

作者: pure_joy | 来源:发表于2018-05-29 16:33 被阅读8次

    创建对象

    把一个类放入到spring容器中,该类称为bean

    <bean id="helloworld" class="com.test.createObject.HelloWorld"></bean>
    

    Spring创建对象的三种方式

    1、构造方法

    <bean id="helloworld" class="com.test.createObject.HelloWorld"></bean>
    

    2、静态工方法

    <bean id="helloworldFactory" class="com.test.createObject.HelloWorldFactory" factory-method="getInstance"></bean>
    

    3、实例工厂方法

    <bean id="helloworldFactory" class="com.test.createObject.HelloWorldFactory"></bean>
    <bean id="helloWorld3" factory-bean="helloWorldFactory" factory-method="getInstance"></bean>
    

    别名

    <alias iname="helloworld"  alias="hello"></alias>
    //name属性的值要与id的值对应
    

    相关文章

      网友评论

          本文标题:Spring创建对象

          本文链接:https://www.haomeiwen.com/subject/disajftx.html