久久久精品一区ed2k-女人被男人叉到高潮的视频-中文字幕乱码一区久久麻豆樱花-俄罗斯熟妇真实视频

spring使用<context:load-time-weaver/>實(shí)現(xiàn)靜態(tài)代理所遇到的問題

本篇內(nèi)容主要講解“spring使用<context:load-time-weaver/>實(shí)現(xiàn)靜態(tài)代理所遇到的問題”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“spring使用<context:load-time-weaver/>實(shí)現(xiàn)靜態(tài)代理所遇到的問題”吧!

創(chuàng)新互聯(lián)公司是一家專業(yè)提供新疆企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、H5開發(fā)、小程序制作等業(yè)務(wù)。10年已為新疆眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。

第一步:

創(chuàng)建要實(shí)現(xiàn)靜態(tài)的類,以及Advice增強(qiáng)類實(shí)現(xiàn),內(nèi)容如下:

需要靜態(tài)代理的類:

public interface IITestBean {
    void test();
}
public class TestBean implements IITestBean {
    @Override
    public void test() {
        System.out.println("test");
    }
}

Advice增強(qiáng)類:

@Aspect
public class AspectTest {

    @Pointcut("execution(* *.test(..))")
    public void test() {
        System.out.println("我切入了");
    }

    @Before("test()")
    public void beforeTest() {
        System.out.println("beforeTest()");
    }
    
    @After("test()")
    public void afterTest() {
        System.out.println("afterTest()");
    }

    @Around("test()")
    public Object aroundTest(ProceedingJoinPoint p) {
        System.out.println("before1");
        Object o = null;
        try {
            o = p.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        System.out.println("after1");
        return o;
    }
}

第二步:

在class目錄下的META-INF(沒有則創(chuàng)建)文件夾下建立aop.xml,內(nèi)容如下

<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
    <weaver>
        <include within="com.zzx.study.aspect.*"/>
    </weaver>

    <aspects>
        <aspect name="com.zzx.study.aspect.AspectTest"/>
    </aspects>
</aspectj>

第三步:

編寫spring的配置spring-aspect.xml,內(nèi)容如下:

<?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"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <bean id="test" class="com.zzx.study.aspect.TestBean"/>
    <context:load-time-weaver/>
</beans>

第四步:

編寫測試類,內(nèi)容如下:

public class AspectTest {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-aspect.xml");
        TestBean bean = (TestBean)context.getBean("test");
        bean.test();
    }
}

第五步:

測試時,需下載并引入org.springframework.instrument.jar文件,在idea中配置如下:

spring使用<context:load-time-weaver/>實(shí)現(xiàn)靜態(tài)代理所遇到的問題

第六步:

運(yùn)行中遇到的問題

問題1:出現(xiàn)了一個java.lang.VerifyError: Expecting a stackmap frame at branch target 7錯誤

解決方法:idea中VM option,需加入-XX:-UseSplitVerifier

spring使用<context:load-time-weaver/>實(shí)現(xiàn)靜態(tài)代理所遇到的問題

問題2:circular advice precedence錯誤

解決方法:

原因Advice增強(qiáng)器AspectTest,必須要按照@Before->@Around->@After編寫代碼,上面代碼調(diào)整順利即可。但是在spring動態(tài)代理沒有該順序不對,不會拋異常。

第七步:

我們可以看到正常的靜態(tài)類代理結(jié)果如下:

spring使用<context:load-time-weaver/>實(shí)現(xiàn)靜態(tài)代理所遇到的問題

到此,相信大家對“spring使用<context:load-time-weaver/>實(shí)現(xiàn)靜態(tài)代理所遇到的問題”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

當(dāng)前標(biāo)題:spring使用<context:load-time-weaver/>實(shí)現(xiàn)靜態(tài)代理所遇到的問題
網(wǎng)站路徑:http://sd-ha.com/article32/jocppc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、定制網(wǎng)站、移動網(wǎng)站建設(shè)、虛擬主機(jī)、全網(wǎng)營銷推廣網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名