日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

spring中基于XML的AOP配置步骤

發布時間:2025/4/16 asp.net 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring中基于XML的AOP配置步骤 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

spring中基于XML的AOP配置步驟





IAccountService.java

package com.itheima.service;/*** 賬戶的業務層接口*/ public interface IAccountService {/*** 模擬保存賬戶*/void saveAccount();/*** 模擬更新賬戶* @param i*/void updateAccount(int i);/*** 刪除賬戶* @return*/int deleteAccount(); }

AccountServiceImpl.java

package com.itheima.service.impl;import com.itheima.service.IAccountService;/*** 賬戶的業務層實現類*/ public class AccountServiceImpl implements IAccountService{@Overridepublic void saveAccount() {System.out.println("執行了保存");}@Overridepublic void updateAccount(int i) {System.out.println("執行了更新"+i);}@Overridepublic int deleteAccount() {System.out.println("執行了刪除");return 0;} }

Logger.java

package com.itheima.utils;/*** 用于記錄日志的工具類,它里面提供了公共的代碼*/ public class Logger {/*** 用于打印日志:計劃讓其在切入點方法執行之前執行(切入點方法就是業務層方法)*/public void printLog(){System.out.println("Logger類中的pringLog方法開始記錄日志了。。。");} }

bean.xml

<?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:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"><!-- 配置srping的Ioc,把service對象配置進來--><bean id="accountService" class="com.itheima.service.impl.AccountServiceImpl"></bean><!-- 配置Logger類 --><bean id="logger" class="com.itheima.utils.Logger"></bean><!--配置AOP--><aop:config><!--配置切面 --><aop:aspect id="logAdvice" ref="logger"><!-- 配置通知的類型,并且建立通知方法和切入點方法的關聯--><aop:before method="printLog" pointcut="execution(* com.itheima.service.impl.*.*(..))"></aop:before></aop:aspect></aop:config></beans>

AOPTest.java

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中基于XML的AOP配置步骤的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。