Spring 3

动态代理

Spring 3_第1张图片

spring基于XML的AOP配置 

1.查找xmlns:app

 2.约束和配置(bean.XML)




    
    

    

    
    

    
    
        
        
            
            
        
    

3.业务层

package com.itheima.service;
// 账户的业务层接口
public interface IAccountService {

   //模拟保存账户 
   void saveAccount();
    /**
     * 模拟更新账户
     * @param i
     */
   void updateAccount(int i);
    /**
     * 删除账户
     * @return
     */
   int  deleteAccount();
}
——————————————————————————————————————————————————————————————————————
package com.itheima.service.impl;

import com.itheima.service.IAccountService;
// 账户的业务层实现类
public class AccountServiceImpl implements IAccountService{

    @Override
    public void saveAccount() {
        System.out.println("执行了保存");
    }

    @Override
    public void updateAccount(int i) {
        System.out.println("执行了更新"+i);
    }

    @Override
    public int deleteAccount() {
        System.out.println("执行了删除");
        return 0;
    }
}

3.日志 

package com.itheima.utils;

/**
 * 用于记录日志的工具类,它里面提供了公共的代码
 */
public class Logger {

    /**
     * 用于打印日志:计划让其在切入点方法执行之前执行(切入点方法就是业务层方法)
     */
    public  void printLog(){
        System.out.println("Logger类中的pringLog方法开始记录日志了。。。");
    }
}

4.测试

package com.itheima.test;

import com.itheima.service.IAccountService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 测试AOP的配置
 */
public class AOPTest {

    public static void main(String[] args) {
        //1.获取容器
        ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
        //2.获取对象
        IAccountService as = (IAccountService)ac.getBean("accountService");
        //3.执行方法
        as.saveAccount();
        as.updateAccount(1);
        as.deleteAccount();
    }
}

你可能感兴趣的:(spring,java,spring,boot)