Spring创建对象

2018-05-29  本文已影响8人  pure_joy

创建对象

把一个类放入到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的值对应
上一篇 下一篇

猜你喜欢

热点阅读