Spring 几种注入方法
2013-11-12 12:05
393 查看
1、set注入方式
2、构造方式注入
3、接口注入
set注入:在当前需要注入类中,提供注入属性和对应属性set方法,在applicationContext.xml文件当前需要注入类中配置<property>即可:
<bean id="helloService" class="com.wq.service.impl.HelloServiceImpl"></bean>
<bean name="/hello" class="com.wq.web.action.HelloAction" autowire="constructor">
<property name="helloService" ref="helloService"></property> //红色为当前类中属性,黑色粗体为上面实例化对象ID
</bean>
构造方法注入:在当前需要注入的类中,提供注入属性和当前类构造方法,构造方法中参数为注入属性。在applicaionContext.xml文件的当前类中。加入属性autowire="constructor"即可:
<bean name="/hello" class="com.wq.web.action.HelloAction" autowire="constructor"> //黑色粗体表明构造方式为构造方法注入。
</bean>
接口注入:
。。。。。。
2、构造方式注入
3、接口注入
set注入:在当前需要注入类中,提供注入属性和对应属性set方法,在applicationContext.xml文件当前需要注入类中配置<property>即可:
<bean id="helloService" class="com.wq.service.impl.HelloServiceImpl"></bean>
<bean name="/hello" class="com.wq.web.action.HelloAction" autowire="constructor">
<property name="helloService" ref="helloService"></property> //红色为当前类中属性,黑色粗体为上面实例化对象ID
</bean>
构造方法注入:在当前需要注入的类中,提供注入属性和当前类构造方法,构造方法中参数为注入属性。在applicaionContext.xml文件的当前类中。加入属性autowire="constructor"即可:
<bean name="/hello" class="com.wq.web.action.HelloAction" autowire="constructor"> //黑色粗体表明构造方式为构造方法注入。
</bean>
接口注入:
。。。。。。
相关文章推荐
- Spring参数注入的几种方法
- 初始化spring容器的几种方法
- spring注入bean进入工具类的静态方法
- Spring中单例bean访问非单例bean的第一种方式:方法注入(转http://blog.csdn.net/ayueiloveyou/archive/2008/08/03/2760473.aspx)
- Spring.Net对方法的注入(学习笔记三)
- spring获取webapplicationcontext,applicationcontext几种方法详解
- Spring基于xml的构造方法注入&setter注入
- Spring 参数注入方法
- Spring依赖注入的三种方式详解之三:工厂方法注入
- servlet让spring自动注入解决方法
- 实例化spring容器applicationContext的几种方法
- 下载spring的几种方法
- Spring 有几种注入方式
- Spring注入Date类型的三种方法总结
- SPRING.NET 1.3.2 学习18--方法注入之IObjectFactoryAware,IObjectNameAware
- spring获取webapplicationcontext,applicationcontext几种方法详解
- AngularJS基础 之 依赖注入的几种方法
- spring+hibernate架构中Dao访问数据库的几种方法
- SPRING.NET 1.3.2 学习19--方法注入之查询方法注入
- Spring4类属性自动装配和方法注入