Spring 1/2 (6), spring

Source: Internet
Author: User

Spring 1/2 (6), spring

1     <bean id="personAction" class="com.lee.spring008.IOC.DI.MVC.PersonAction">2         <property name="stuService" ref="stuService"></property>3     </bean>4     <bean id="stuService" class="com.lee.spring008.IOC.DI.MVC.StuServiceImpl">5         <property name="stuDAO" ref="stuDAO"></property>6     </bean>7     <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

 1 package com.lee.spring008.IOC.DI.MVC; 2  3 public class PersonAction { 4  5     public IStuService stuService; 6  7     public void displaySave() { 8         stuService.saveStu(); 9     }10 11     public IStuService getStuService() {12         return stuService;13     }14 15     public void setStuService(IStuService stuService) {16         this.stuService = stuService;17     }18 19 }

StuDAOImpl. java

 1 package com.lee.spring008.IOC.DI.MVC; 2  3 public class StuDAOImpl implements IStuDAO { 4  5     @Override 6     public void saveStu() { 7         System.out.println("dao: saving stu..."); 8     } 9 10 }

StuServiceImpl. java

 1 package com.lee.spring008.IOC.DI.MVC; 2  3 public class StuServiceImpl implements IStuService { 4  5     public IStuDAO stuDAO; 6      7     @Override 8     public void saveStu() { 9         System.out.println("service: saving stu...");10         stuDAO.saveStu();11     }12 13     public IStuDAO getStuDAO() {14         return stuDAO;15     }16 17     public void setStuDAO(IStuDAO stuDAO) {18         this.stuDAO = stuDAO;19     }20 21 }

Test:

1 @Test2     public void testPersonAction() {3         ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");4         PersonAction person = (PersonAction)context.getBean("personAction");5         person.displaySave();6     }

 

Github address: https://github.com/leechenxiang/maven-spring001-helloworld

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.