<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 }
點擊查看更多內(nèi)容
風(fēng)間影月說
去圍觀
創(chuàng)業(yè)公司技術(shù)總監(jiān), 10年+開發(fā)和技術(shù)管理經(jīng)驗。SUN認(rèn)證SCJP、PMP、MCP認(rèn)證。主要從事后端技術(shù)和架構(gòu)領(lǐng)域,有豐富的電商平臺與物流平臺核心系統(tǒng)的架構(gòu)設(shè)計和開發(fā)經(jīng)驗。
評論
評論
共同學(xué)習(xí),寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少


贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦