国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

spring-aop示例

2019-11-14 15:02:53
字體:
來源:轉載
供稿:網友

 具體案例放在github上,主要是jar包在上面

https://github.com/guoyansi/sPRing-aop-example

 

knights.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:p="http://www.springframework.org/schema/p"         xmlns:context="http://www.springframework.org/schema/context"        xmlns:mvc="http://www.springframework.org/schema/mvc"         xmlns:tx="http://www.springframework.org/schema/tx"         xmlns:aop="http://www.springframework.org/schema/aop"    xsi:schemaLocation="          http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans.xsd         http://www.springframework.org/schema/context         http://www.springframework.org/schema/context/spring-context.xsd         http://www.springframework.org/schema/mvc        http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd                http://www.springframework.org/schema/tx        http://www.springframework.org/schema/tx/spring-tx.xsd        http://www.springframework.org/schema/aop        http://www.springframework.org/schema/aop/spring-aop.xsd">        <bean id="knight" class="p1.BraveKnight">            <constructor-arg ref="quest" />        </bean>        <bean id="quest" class="p1.SlayDragonQuest"></bean>                <bean id="minstrel" class="p1.Minstrel"></bean>                <aop:config>            <aop:aspect ref="minstrel">                <aop:pointcut id="embark" expression="execution(* *.embarkOnQuest(..))" />                <aop:before pointcut-ref="embark" method="singBeforeQuest"/>                <aop:after pointcut-ref="embark" method="singAfterQuest"/>            </aop:aspect>        </aop:config>              </beans>

IQuest.java

package p1;/** * 探險 * */public interface IQuest {    void embark();}

IKnight.java

package p1;public interface IKnight {    void embarkOnQuest();}

BraveKnight.java

package p1;/** * 騎士 * */public class BraveKnight implements IKnight{    private IQuest quest;        public BraveKnight(IQuest quest){        this.quest=quest;            }    @Override    public void embarkOnQuest (){        quest.embark();    }    }

SlayDragonQuest.java

package p1;public class SlayDragonQuest implements IQuest{    @Override    public void embark() {        System.out.println("SlayDragonQuest的embark......");            }}

Minstrel.java

package p1;public class Minstrel {    public void singBeforeQuest(){        System.out.println("探險之前...");    }    public void singAfterQuest(){        System.out.println("探險之后......");    }    }
package p1;import org.springframework.context.applicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Run {    public static void main(String[] args) {        ApplicationContext context=new ClassPathXmlApplicationContext("classpath*:knights.xml");        IKnight knight=(IKnight)context.getBean("knight");        knight.embarkOnQuest();    }}

執行run的結果:

上面是一個完整的例子.如果沒有commons-logging.jar

控制臺上的那些紅色字樣就不會輸出,還會出現異常.

如果沒有aopalliance.jar:           

nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice

如果沒有aspectjweaver.jar

nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 隆尧县| 乌鲁木齐县| 盖州市| 江口县| 大石桥市| 大埔区| 印江| 永登县| 措勤县| 云南省| 盱眙县| 鄢陵县| 宜阳县| 普洱| 巴塘县| 葵青区| 上思县| 龙泉市| 闽清县| 连江县| 罗定市| 崇礼县| 开阳县| 故城县| 修水县| 塔城市| 宜黄县| 安乡县| 巴塘县| 黔西县| 天峻县| 海淀区| 右玉县| 博客| 伽师县| 射洪县| 甘谷县| 乌拉特中旗| 姚安县| 承德市| 灵台县|