Package Com.fxr.spring.action;import Java.util.list;import Javax.annotation.resource;import Org.springframework.context.annotation.scope;import Org.springframework.stereotype.controller;import Com.fxr.spring.model.user;import Com.fxr.spring.service.UserService; @Controller ("useraction")// The MVC control layer typically uses @controller@scope ("prototype")//set to multiple mode public class Useraction {private User u;private int id;private UserService userservice;private list<string>names;public list<string> getNames () {return names;} public void Setnames (list<string> names) {this.names = names;} Public useraction () {}public User Getu () {return u;} public void SetU (User u) {this.u = u;} public int getId () {return ID;} public void setId (int id) {this.id = ID;} Public UserService Getuserservice () {return userservice;} @Resourcepublic void Setuserservice (UserService userservice) {this.userservice = UserService;} public void Add () {userservice.add (U);} public void Delete () {userservice.delete (id);}} =============================================package Com.fxr.spring.dao;import Com.fxr.spring.model.user;public interface IUserDao {public void Add (User u);p ublic void Delete (int id);} =============================================package Com.fxr.spring.dao;import Org.springframework.stereotype.component;import Org.springframework.stereotype.repository;import com.fxr.spring.model.user;//@Component ("Userdao")//Common creation Bean annotation@repository ("Userdao")//@ Repository is generally used for DAO injection public class Userdao implements iuserdao{@Overridepublic void Add (User u) {System.out.println ("add" +U);} @Overridepublic void Delete (int id) {System.out.println ("delete" +id);}} ================================================package Com.fxr.spring.dao;import Javax.annotation.Resource; Import Org.springframework.stereotype.repository;import Com.fxr.spring.model.user;import Com.fxr.spring.util.Logger, @Repository ("Userproxydao") public class Userproxydao implements Iuserdao{private Iuserdao user;public Iuserdao GetUser () {return user;} @Resourcepublic void SETUser (Iuserdao user) {this.user = user;} @Overridepublic void Add (User u) {logger.info ("Add Users"); System.out.println ("add" +u); @Overridepublic void Delete (int id) {logger.info ("delete user"); System.out.println ("delete" +id);}} ============================================package Com.fxr.spring.model;public class User {private int id;private String name;public User (int id,string name) {this.id = Id;this.name = name;} Public User () {}public int getId () {return ID;} public void setId (int id) {this.id = ID;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;} @Overridepublic String toString () {return "User [id=" + ID + ", name=" + name + "]";}} ===========================================package Com.fxr.spring.service;import Com.fxr.spring.dao.UserDao; Import Com.fxr.spring.model.user;public interface Iuserservice {public void Add (User u);p ublic void Delete (int id);} ================================================package Com.fxr.spring.service;import Javax.annotation.Resource; ImPort Org.springframework.stereotype.component;import Org.springframework.stereotype.service;import Com.fxr.spring.dao.iuserdao;import com.fxr.spring.dao.userdao;import Com.fxr.spring.model.User; @Component (" UserService ") @Service (" UserService ")//Business layer generally uses @servicepublic class UserService implements Iuserservice{private Iuserdao userdao;public Iuserdao Getuserdao () {return userdao;} @Resource (name= "Userproxydao") public void Setuserdao (Iuserdao userdao) {This.userdao = Userdao;} @Overridepublic void Add (User u) {userdao.add (U);} @Overridepublic void Delete (int id) {userdao.delete (id);}} ==============================================package Com.fxr.spring.util;public class Logger {public static void info (String str) {System.out.println (str);}} ===============================================package Com.fxr.spring.test;import Org.springframework.beans.factory.beanfactory;import Org.springframework.context.support.classpathxmlapplicationcontext;import com.fxr.spring.action.UserAction; Import COM.FXR.SPRIng.model.helloworld;import Com.fxr.spring.model.user;public class Test {private static beanfactory factory = new Classpathxmlapplicationcontext ("Bean.xml");p ublic static void Main (string[] args) {////creates a class//helloworld Hello = ( HelloWorld) Factory.getbean ("HelloWorld");//hello.say ();//Create a class useraction UA1 = (useraction) Factory.getbean (" Useraction "); User U = New User (1, "Zhang San"); Ua1.setu (U); SYSTEM.OUT.PRINTLN (u); Ua1.add ()//useraction ua2 = (useraction) factory.getbean ("Useraction");//ua2.add ();}} =======================================<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "/http Www.springframework.org/schema/beans "xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "xmlns:context=" http ://www.springframework.org/schema/context "xsi:schemalocation=" Http://www.springframework.org/schema/beans htt P://www.springframework.org/schema/beans/spring-beans-3.0.xsd Http://www.springframework.org/schema/context http://www.springframework.org/Schema/context/spring-context-3.0.xsd "> <!--Open Spring Annotation Support--<context:annotation-config/> <!--set spring to go to which packages to find annotation---<context:component-scan base-package= "com.fxr.spring"/> </be Ans>
Spring's AOP static proxy