Spring创建对象

创建对象

把一个类放入到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的值对应
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容