当持久层 dao的dao是一个接口,怎样依赖注入

2010年2月 Java大版内专家分月排行榜第二
2011年7月 Java大版内专家分月排行榜第三2010年1月 Java大版内专家分月排行榜第三2009年12月 Java大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。-------------
新增文件夹...
新增文件夹
(多个标签用逗号分隔)
Spring的核心机制依赖注入简介.doc
Spring的核心机制依赖注入简介收藏Spring能有效地组织J2EE应用各层的对象。不管是控制层的Action对象,还是业务层的Service对象,还是持久层的DAO对象,都可在Spring的管理下有机地协调、运行。Spring将各层的对象以松耦合的方式组织在一起,Action对象无须关心Service对象的具体实现,Service对象无须关心持久层对象的具体实现,各层对象的调用完全面向接口。当
Spring的核心机制依赖注入简介收藏Spring能有效地组织J2EE应用各层的对象。不管是控制层的Action对象,还是业务层的Service对象,还是持久层的DAO对象,都可在Spring的管理下有机地协调、运行。Spring将各层的对象以松耦合的方式组织在一起,Action对象无须关心Service对象的具体实现,Service对象无须关心持久层对象的具体实现,各层对象的调用完全面向接口。当系统需要重构时,代码的改写量将大大减少。&&
加载中...!如果长时间没有加载,请刷新页面
下载本文档需要登录,并付出相应积分()。
文件大小:58.00 KB
所需积分:& 5
相关资讯  — 
相关讨论话题  — 
浏览:2977次&& 下载:0次
上传时间: 11:19:26
同类热门文档
0次浏览 &81次下载
0次浏览 &119次下载
0次浏览 &137次下载
13439次浏览 &38次下载
0次浏览 &33次下载
0次浏览 &17次下载
相关经验 -
& 3人评&95页
& 9人评&95页
& 10人评&95页
& 0人评&2页
& 11人评&10页
OPEN-OPEN, all rights reserved.spring依赖注入之构造器方式注入 - Ω半个草莓Ω - ITeye博客
博客分类:
Spring2.5的注入依赖(DI)主要有三种注入方式,即构造器注入、Setter注入和使用注解方式;注入依赖可以分为手工装配和自动装配,spring开发团队建议使用手工装配。
今天主要说说构造器注入
基于构造器的DI通过调用带参数的构造器来实现,每个参数代表着一个依赖。
,spring是基于接口编程的,请注意接口
public class StudentDao implements IStudentDao {
public void saveStudent() {
System.out.println("成功保存一个学生信息");
public class StudentService implements IStudentService {
private IStudentDao studentD
public StudentService(IStudentDao studentDao,String id){
this.studentDao = studentD
public void saveStudent() {
studentDao.saveStudent();
System.out.print(",ID为:"+id);
3. spring配置
&bean id="studentDao" class="com.wch.dao.impl.StudentDao"&&/bean&
&bean id="studentService" class="com.wch.service.impl.StudentService"&
&constructor-arg index="0" type="com.wch.dao.IStudentDao" ref="studentDao" /&
&constructor-arg index="1" value="123456" type="java.lang.String"&&/constructor-arg&
用'type'属性来显式指定那些构造参数的类型
index属性来显式指定构造参数的索引,从0开始
4. 经行测试,代码如下
public class TestSpringBuild extends TestCase{
private AbstractApplicationContext ctx =
public void setUp() throws Exception {
//ctx = new ClassPathXmlApplicationContext("bean.xml");
ctx = new FileSystemXmlApplicationContext("classpath:bean.xml");
public void tearDown() throws Exception {
ctx.close();
@Test public void testBuild(){
StudentService studentService = (StudentService)ctx.getBean("studentService");
studentService.saveStudent();
浏览: 182031 次
来自: 湖南。邵阳
为什么我的不行呢
特别不错,解决了

我要回帖

更多关于 dao接口 的文章

 

随机推荐