Created
November 3, 2016 13:04
-
-
Save victorjspinto/2383793155b775f319b3a53239e10cce to your computer and use it in GitHub Desktop.
AOP - Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.springaction.knights; | |
public class BraveKnight implements Knight { | |
private Quest quest; | |
private Minstrel minstrel; | |
public BraveKnight(Quest quest, Minstrel minstrel) { | |
this.quest = quest; | |
this.minstrel = minstrel; | |
} | |
/* should Knight manage his own minstrel??? */ | |
public void embarkQuest() throws QuestException { | |
minstrel.singBeforeQuest(); | |
quest.embark(); | |
minstrel.singAfterQuest(); | |
} | |
} | |
===================== ApplicationContext.xml ===================== | |
<beans> | |
<bean id="knight" class="com.springaction.knights.BraveKnight"> | |
<constructor-arg ref="quest"/> | |
</bean> | |
<bean id="quest" class="com.springaction.knights.SlayDragonQuest"> | |
<constructor-arg value="#(T(System.out)"/> | |
</bean> | |
<bean id="minstrel" class="com.springaction.knights.Minstrel"> | |
<constructor-arg value="#(T(System.out)"/> | |
</bean> | |
<aop:config> | |
<aop:aspect ref="minstrel"> | |
<aop:point-cut id="embark" | |
expression="execution (* *.embarkOnQuest(..))"/> | |
<aop:before pointcut-ref="embark" method="singBeforeQuest"/> | |
<aop:after pointcut-ref="embark" method="singAfterQuest"/> | |
</aop:aspect> | |
</aop:config> | |
</beans> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment