freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

通過代碼實例跟我學(xué)面向方面編程從入門到精通——在項目中實現(xiàn)springaop的around類型通知advice的應(yīng)用實例-在線瀏覽

2024-11-14 09:56本頁面
  

【正文】 精心創(chuàng)作的優(yōu)秀程序員 職業(yè)提升必讀系列資料 楊教授工作室,版權(quán)所有,盜版必究 , 6/21 頁 ( 1)主要的作用 它是一個工廠類,創(chuàng)建 Aop Proxy 代理對象 實例。在配置 ProxyFactoryBean 時,需要設(shè)定與 AOP 實現(xiàn)相關(guān)的重要屬性,比如 ProxyInterface、 interceptorNames 和 target 等。 為該 Project 添加一個對象管理的 *.xml 文件(名稱為 ) ( 1)新增加一個 的 XML 配置文件 采用 import resource=/方式相互串接在一起。 ( 3) 的 XML配置文件 具體的 代碼示例 ?xml version= encoding=UTF8? !DOCTYPE beans PUBLIC //SPRING//DTD BEAN//EN beans bean id=logInterceptor class=/ bean id=oneAccountInfoManageBean class=/ bean id=oneAccountInfoManageBeanProxy class= property name=proxyInterfaces value/value /property property name=target ref bean=oneAccountInfoManageBean/ /property property name=interceptorNames list valuelogInterceptor/value /list /property /bean /beans ( 4)所應(yīng)該要 注意 的問題 1) 利用 proxyInterfaces 屬性來設(shè)定所要代理的接口類型,如果沒有設(shè)定這個屬性,則楊教授工作室 精心創(chuàng)作的優(yōu)秀程序員 職業(yè)提升必讀系列資料 楊教授工作室,版權(quán)所有,盜版必究 , 8/21 頁 會基于 targat 屬性所設(shè)定的 bean 來自動偵測接口。 本例中的 interceptorNames 屬性接收的是 String 文字指定的 bean 名稱,而不使用ref標(biāo)簽來引用目標(biāo) bean。如果任何 advisor 本身是一個原型,則每次都返回一個獨立實例,因此它必須能夠從工廠里獲得原型的一個實例;保存一個引用是不夠的。 因此,在 XML 配置文件中就不需要配置“連接點”。 package 。 import 。 import 。 AccountInfoManageInterface oneAccountInfoManageBean= new AccountInfoManageImplement()。 (logInterceptor)。 (12345678,)。 } public static void main(String[] args) { new TestLogInterceptorBySpringAOP()。 ( 4) 執(zhí)行 測試類的 代碼,將產(chǎn)生出下面的結(jié)果。 ( 2)測試類 TestLogInterceptorBySpringAOP 的代碼示例 package 。 import 。 public class TestLogInterceptorBySpringAOP { 楊教授工作室 精心創(chuàng)作的優(yōu)秀程序員 職業(yè)提升必讀系列資料 楊教授工作室,版權(quán)所有,盜版必究 , 11/21 頁 public TestLogInterceptorBySpringAOP() { AccountInfoManageInterface oneAccountInfoManageBeanProxy=null。 // ApplicationContext ctx=new FileSystemXmlApplicationContext()。 (12345678,)。 } public static void main(String[] args) { new TestLogInterceptorBySpringAOP()。因為在 Spring 中, Spring 管理的對象都必須通過這個 ApplicationContext 工廠來創(chuàng)建或者通過注入的方式來獲得。 ( 3) 執(zhí)行 本示例的測試代碼 此時,將在 Eclipse 的控制臺窗口中出現(xiàn)下面的提示 。并且采用 XML 配置的方式比直接采用編程的方式要簡單! 注意: 利用上面 的 around 形式的通知 ,我們不僅可以實現(xiàn)上面類似功能要求的實現(xiàn)。 在應(yīng)用 Arround 類型的攔截器時一定要在攔截器中對原始的業(yè)務(wù)方法(也就是 被攔截的目標(biāo)方法)進(jìn)行調(diào)用,否則原始的業(yè)務(wù)方法沒有執(zhí)行! package 。 import 。 import 。 楊教授工作室 精心創(chuàng)作的優(yōu)秀程序員 職業(yè)提升必讀系列資料 楊教授工作室,版權(quán)所有,盜版必究 , 13/21 頁 public LogInterceptor() { } public Object invoke(MethodInvocation methodInvocation) throws Throwable { boolean methodReturnBoolean=false。 String methodName=().getName()。 try { (500)。 } try{ returnResult = ()。 try { (500)。 } } finally{ if(methodReturnBoolean){ (, methodName+功能方法執(zhí)行結(jié)束,并且已經(jīng)成功地執(zhí)行了! + () + \n)。 } } return returnResult。 1 課后作業(yè): 利用 Arround 類型的攔截器的原理,設(shè)計一個實現(xiàn)“事務(wù)控制”的攔截器,實現(xiàn)對項目中的各個 DAO 進(jìn)行統(tǒng)一的事務(wù)控制。 但此時必須要通過 Java 中的反射技術(shù)實現(xiàn)對目標(biāo) DAO 類中的數(shù)據(jù)訪問方法進(jìn)行調(diào)用,并將數(shù)據(jù)庫連接對象傳遞給 DAO 類中的數(shù)據(jù)訪問方法。//對 DAO 類中的方法調(diào)用 //關(guān)閉數(shù)據(jù)庫連接對象 } 應(yīng)用 RegexpMethodPointcutAdvisor 裝配器組件提高攔截的靈活性 Spring
點擊復(fù)制文檔內(nèi)容
環(huán)評公示相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1