Spring one or two things (6)-IOC MVC Simple setup

Source: Internet
Author: User

1     <BeanID= "Personaction"class= "Com.lee.spring008.IOC.DI.MVC.PersonAction">2         < Propertyname= "Stuservice"ref= "Stuservice"></ Property>3     </Bean>4     <BeanID= "Stuservice"class= "Com.lee.spring008.IOC.DI.MVC.StuServiceImpl">5         < Propertyname= "Studao"ref= "Studao"></ Property>6     </Bean>7     <BeanID= "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  PackageCom.lee.spring008.IOC.DI.MVC;2 3  Public classpersonaction {4 5      PublicIstuservice Stuservice;6 7      Public voidDisplaysave () {8 Stuservice.savestu ();9     }Ten  One      PublicIstuservice Getstuservice () { A         returnStuservice; -     } -  the      Public voidSetstuservice (Istuservice stuservice) { -          This. Stuservice =Stuservice; -     } -  +}

Studaoimpl.java

1  PackageCom.lee.spring008.IOC.DI.MVC;2 3  Public classStudaoimplImplementsIstudao {4 5 @Override6      Public voidSavestu () {7System.out.println ("Dao:saving stu ...");8     }9 Ten}

Stuserviceimpl.java

1  PackageCom.lee.spring008.IOC.DI.MVC;2 3  Public classStuserviceimplImplementsIstuservice {4 5      PublicIstudao Studao;6     7 @Override8      Public voidSavestu () {9System.out.println ("Service:saving stu ...");Ten Studao.savestu (); One     } A  -      PublicIstudao Getstudao () { -         returnStudao; the     } -  -      Public voidSetstudao (Istudao Studao) { -          This. Studao =Studao; +     } -  +}

Test:

1 @Test 2      Public void testpersonaction () {3         New Classpathxmlapplicationcontext ("Applicationcontext.xml"); 4         Personaction person = (personaction) context.getbean ("Personaction"); 5         Person.displaysave (); 6     }

GitHub Address: Https://github.com/leechenxiang/maven-spring001-helloworld

Spring one or two things (6)-IOC MVC Simple setup

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.