免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Spring AOP實(shí)現(xiàn)日志輸出
================接口類TimeBookInterface ==============
package com.gc.action.springaop;
/**
* 接口類
* @author yltd
*
*/
public interface TimeBookInterface {
public void doSameing(String name);
}
==============接口實(shí)現(xiàn)類TimeBookImpl ======================
package com.gc.action.springaop;
/**
* 接口實(shí)現(xiàn)類
* @author yltd
*
*/
public class TimeBookImpl implements TimeBookInterface {
@Override
public void doSameing(String name) {
System.out.println(name);
}
}
===============日志輸出類LogAround ==================
package com.gc.action.springaop;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
/**
* AOP實(shí)現(xiàn)輸出日志
* @author yltd
*
*/
public class LogAround implements MethodInterceptor {
Logger logger =Logger.getLogger(this.getClass().getName());
@Override
public Object invoke(MethodInvocation arg) throws Throwable {
logger.log(Level.INFO, "開始。。。");
Object obj = arg.proceed();
logger.log(Level.INFO, "結(jié)束。。。");
return obj;
}
}
=============XML配置文件config.xml==================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 負(fù)責(zé)國(guó)際化支持 -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<!-- 國(guó)際化支持的定義在文件名為messages的文件中 -->
<property name="basename">
<value>messages</value>
</property>
</bean>
<bean id="log" class="com.gc.action.springaop.LogAround"></bean>
<bean id="timeBook" class="com.gc.action.springaop.TimeBookImpl"></bean>
<bean id="logProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>com.gc.action.springaop.TimeBookInterface</value>
</property>
<property name="target">
<ref bean="timeBook"/>
</property>
<!-- 指定要代理的類 -->
<property name="interceptorNames">
<list>
<value>log</value>
</list>
</property>
</bean>
</beans>
====================測(cè)試類TestMain ================
package com.gc.action.springaop;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
/**
* 測(cè)試類
* @author yltd
*
*/
public class TestMain {
public static void main(String[] args) {
ApplicationContext ac =new FileSystemXmlApplicationContext("classpath:/SpringConfig.xml");
TimeBookInterface tbi=(TimeBookInterface) ac.getBean("logProxy");
tbi.doSameing("張藝馨");
}
}
====================結(jié)果======================
- Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@4e515669: startup date [Fri Oct 19 16:13:27 CST 2018]; root of context hierarchy
- Loading XML bean definitions from class path resource [SpringConfig.xml]
- 開始。。。
張藝馨
- 結(jié)束。。。
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Spring自動(dòng)接線…將源類傳遞給自動(dòng)接線類
spring boot 實(shí)際應(yīng)用(一) 內(nèi)置tomcat 實(shí)現(xiàn)JMX配置
ibatis簡(jiǎn)單分頁
CXF之六(對(duì)請(qǐng)求參數(shù)和返回給客戶數(shù)據(jù)處理)
AOP以及其在Spring中的應(yīng)用(二)
Spring Cache 介紹
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服