<bean id="personAction" class="com.lee.spring008.IOC.DI.MVC.PersonAction">
<property name="stuService" ref="stuService"></property>
</bean>
<bean id="stuService" class="com.lee.spring008.IOC.DI.MVC.StuServiceImpl">
<property name="stuDAO" ref="stuDAO"></property>
</bean>
<bean id="stuDAO" class="com.lee.spring008.IOC.DI.MVC.StuDAOImpl"></bean>
IStuDAO.java
1 package com.lee.spring008.IOC.DI.MVC;
2
3 public interface IStuDAO {
4 public void saveStu();
5 }
IStuService.java
1 package com.lee.spring008.IOC.DI.MVC;
2
3 public interface IStuService {
4 public void saveStu();
5 }
PersonAction.java
```package com.lee.spring008.IOC.DI.MVC;
public class StuDAOImpl implements IStuDAO {
@Override
public void saveStu() {
System.out.println("dao: saving stu...");
}
}
StuServiceImpl.java
package com.lee.spring008.IOC.DI.MVC;
public class StuServiceImpl implements IStuService {
public IStuDAO stuDAO;
@Override
public void saveStu() {
System.out.println("service: saving stu...");
stuDAO.saveStu();
}
public IStuDAO getStuDAO() {
return stuDAO;
}
public void setStuDAO(IStuDAO stuDAO) {
this.stuDAO = stuDAO;
}
}
测试:
1 @Test
2 public void testPersonAction() {
3 ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
4 PersonAction person = (PersonAction)context.getBean("personAction");
5 person.displaySave();
6 }
点击查看更多内容
风间影月说
去围观
创业公司技术总监, 10年+开发和技术管理经验。SUN认证SCJP、PMP、MCP认证。主要从事后端技术和架构领域,有丰富的电商平台与物流平台核心系统的架构设计和开发经验。
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦