Spring中的自动代理

 

package com.gc.impl;

import org.apache.log4j.Level;

public interface TimeBookInterface {
	public void doAuditing(String name);
    //刚开始时,这里一直出错,后添加import org.apache.log4j.Level;OK!
	public void doCheck(String name);
}


 

 

package com.gc.action;

import com.gc.impl.TimeBookInterface;

public class TimeBook implements TimeBookInterface{
	public void doAuditing(String name)
	{
		System.out.println("审核数据的相关程序正在执行……");
	}
	public void doCheck(String name)
	{
		System.out.println("财务关帐的相关程序正在执行……");
	}
}


 

 

package com.gc.action;

import java.lang.reflect.Method;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.aop.MethodBeforeAdvice;

public class LogBefore implements MethodBeforeAdvice
{
    private Logger logger=Logger.getLogger(this.getClass().getName());
    
    public void before(Method method,Object[]args,Object target)throws Throwable
    {
    	logger.log(Level.INFO,args[0]+"开始审核数据……");
    }
}


 

 

package com.gc.action;

import java.lang.reflect.Method;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.aop.AfterReturningAdvice;

public class LogAfter implements AfterReturningAdvice
{
   private Logger logger=Logger.getLogger(this.getClass().getName());
   
   public void afterReturning(Object object,Method method,Object[]args,Object target)throws Throwable
   {
	   logger.log(Level.INFO,args[0]+"审核数据结束……");
	   
   }
}


 

 

     
     
  
      
      
    
       
       
       
        
        
         
         HelloWorld
        
        
    
       
         
    
       
       
      
        
        
    
        
        
       
       
  
      
      
  
      
      
  
  
      
       
  
      
       
  
  
      
      
  
  
      
      
  
      
      
    
       
       
       
        
        
    
        
        
       
       
    
       
       
       
        
        
         
         .*do.*
        
        
    
       
       
  
      
      
  
  
      
      
  
      
      
    
       
       
       
        
        
    
        
        
       
       
    
       
       
       
        
        
         
         .*do.*
        
        
    
       
       
  
      
      
 
     
     


 

 

package com.gc.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.gc.impl.FinanceInterface;
import com.gc.impl.TimeBookInterface;

public class TestHelloWorld 
{
    public static void main(String args[])    //throws InstantiationException,IllegalAccessException,ClassNotFoundException
    {
    	ApplicationContext actx=new FileSystemXmlApplicationContext("config.xml");
    	TimeBookInterface timeBookProxy=(TimeBookInterface)actx.getBean("timeBook");
    	timeBookProxy.doAuditing("张三");
}
}


 

 

package com.gc.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.gc.impl.FinanceInterface;
import com.gc.impl.TimeBookInterface;

public class TestHelloWorld 
{
    public static void main(String args[])    //throws InstantiationException,IllegalAccessException,ClassNotFoundException
    {
    	ApplicationContext actx=new FileSystemXmlApplicationContext("config.xml");
    	TimeBookInterface timeBookProxy=(TimeBookInterface)actx.getBean("timeBook");
    	timeBookProxy.doCheck("张三");
}
}


 

 

        
        
  
         
         
    
          
          
       
           
           
            
            HelloWorld
           
           
    
          
            
    
          
          
      
           
           
    
           
           
          
          
  
         
         
  
         
         
  
  <!--  
         
          -->
  
         
          
  
  
         
         
  
  
         
         
  
         
         
    
          
          
       
           
           
    
           
           
          
          
    
          
          
       
           
           
            
            .*doCheck.*
           
           
    
          
          
  
         
         
  
  
         
         
  
         
         
    
          
          
       
           
           
    
           
           
          
          
    
          
          
       
           
           
            
            .*doAuditing.*
           
           
    
          
          
  
         
         
 
        
        


 

package com.gc.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.gc.impl.FinanceInterface;
import com.gc.impl.TimeBookInterface;

public class TestHelloWorld 
{
    public static void main(String args[])    //throws InstantiationException,IllegalAccessException,ClassNotFoundException
    {
    	ApplicationContext actx=new FileSystemXmlApplicationContext("config.xml");
    	TimeBookInterface timeBookProxy=(TimeBookInterface)actx.getBean("timeBook");
    	timeBookProxy.doCheck("张三");
    }
}


 

package com.gc.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.gc.impl.FinanceInterface;
import com.gc.impl.TimeBookInterface;

public class TestHelloWorld 
{
    public static void main(String args[])    //throws InstantiationException,IllegalAccessException,ClassNotFoundException
    {
    	ApplicationContext actx=new FileSystemXmlApplicationContext("config.xml");
    	TimeBookInterface timeBookProxy=(TimeBookInterface)actx.getBean("timeBook");
    	timeBookProxy.doAuditing("张三");
}
}


Invalid property 'pattens' of bean class [org.springframework.aop.support.RegexpMethodPointcutAdvisor]: Bean property 'pattens' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值