Spring Setter Method Injection

Source: Internet
Author: User

Package Entity;public class User {private string Id;private string Name;public string GetId () {return ID;} public void SetId (String id) {this.id = ID;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;}}

Package Dao;public interface Userdao {public void Saveuser ();p ublic void Getuserbyid (int id);}

Package Dao.imp;import DAO. Userdao;public class Userdaoimp implements userdao{@Overridepublic void Saveuser () {//TODO auto-generated method Stubsys Tem.out.println ("--------Save user------");} @Overridepublic void Getuserbyid (int id) {//TODO auto-generated method stub}}

Package Service;public interface UserService {public void Saveuser ();p ublic void Getuserbyid (int id);}

Package Service.imp;import DAO. Userdao;import service. Userservice;public class Userserviceimp implements Userservice{private Userdao userdao;public Userdao GetUserDao () { return Userdao;} public void Setuserdao (Userdao userdao) {This.userdao = Userdao;} @Overridepublic void Saveuser () {//TODO auto-generated method StubSystem.out.println ("SAVE USER"); @Overridepublic void Getuserbyid (int id) {//TODO auto-generated method stub}}

Package Action;import Service. Userservice;public class Useraction {private UserService userservice;public userservice Getuserservice () {return UserService;} public void Setuserservice (UserService userservice) {this.userservice = UserService;} Public String Saveuser () {userservice.saveuser (); return null;}}

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/beans/spring-beans.xsd "><bean id=" Userdao "class=" dao.imp.UserDaoImp "></bean><bean id=" UserService "class=" service.imp.UserServiceImp "><property name=" Userdao "ref= "Userdao" ></property></bean><bean id= "Useraction" class= "action. Useraction "><property name=" UserService "ref=" UserService "></property></bean></beans>

Spring Setter Method Injection

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.