Spring(3)--Lookup Method Injection - flowerkn...

来源:百度文库 编辑:神马文学网 时间:2024/05/23 19:30:04
Spring(3)--Lookup Method Injection 收藏
 Message.javaview plaincopy to clipboardprint?
public class Message {  
    public void play(){  
        System.out.println(new Date());  
    }  

public class Message {
 public void play(){
  System.out.println(new Date());
 }
}  MessageManager.javaview plaincopy to clipboardprint?
public abstract class MessageManager {  
    public void display() {  
        Message m = createMessage();  
        m.play();  
    }  
 
    public abstract Message createMessage();  

public abstract class MessageManager {
 public void display() {
  Message m = createMessage();
  m.play();
 } public abstract Message createMessage();
} context.xmlview plaincopy to clipboardprint?
    lazy-init="default" autowire="default" dependency-check="default"> 
 
 
     
 
   lazy-init="default" autowire="default" dependency-check="default">
 

 
  
 
对于Lookup Method Injection,spring将使用CGLIB产生一个MessageManager子类实现,并且在每次调用createMessage方法时,建立一个Message对象并传回。需要使用cglib.jar库,一般包含在Spring AOP套件中。Lookup Method Injection是Spring提供的Method Injection方案之一,它可以指令方法createMessage(),由spring提供实现,将执行的Message对象注入MessageManager之中。 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/flowerknight/archive/2009/06/18/4281323.aspx