Hi i am trying the below sample AOP application . the application not throwing any exceptions but the AOP advices not getting called
here the sample code follows
sampleAOP.xml is in C: drive(its getting loaded, no issue in loading)
HolyGrail.javaCode:<?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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <bean id="quest" class="SampleAOP.HolyGrailQuest" /> <bean id="knight" class="SampleAOP.KnightOfTheRoundTable"> <constructor-arg value="Ranadheer" /> <property name="quest" ref="quest" /> </bean> <bean id="minstrel" class="SampleAOP.Minstrel"/> <aop:config> <aop:aspect ref="minstrel"> <aop:pointcut id="questPointcut" expression="execution(* *.embarkOnQuest(..)) and target(bean)" /> <aop:before method="singBefore" pointcut-ref="questPointcut" arg-names="bean" /> <aop:after-returning method="singAfter" pointcut-ref="questPointcut" arg-names="bean" /> </aop:aspect> </aop:config> </beans>
HolyGrailQuest.javaCode:package SampleAOP; public class HolyGrail { public void found(){ System.out.println("The Grail is Found,Hahahaha................."); } }
Knight.javaCode:package SampleAOP; public class HolyGrailQuest implements Quest { public HolyGrail embark() { return new HolyGrail(); } }
KnightOfTheRoundTable.javaCode:package SampleAOP; public interface Knight { HolyGrail embarkOnQuest(); }
Minstrel.javaCode:package SampleAOP; public class KnightOfTheRoundTable implements Knight{ private String name; private Quest quest; public KnightOfTheRoundTable(String name){ this.name=name; } public HolyGrail embarkOnQuest() { // TODO Auto-generated method stub return quest.embark(); } public void setQuest(Quest quest){ this.quest=quest; } }
Quest.javaCode:package SampleAOP; import org.apache.log4j.Logger; public class Minstrel { private static final Logger SONG=Logger.getLogger(Minstrel.class); public void singBefore(Knight knight){ System.out.println("is so brave"); } public void singAfter(Knight knight){ System.out.println("did embark on the grail"); } }
and i dont know how to run the application, so i have written class MainClass and invoking all possible beans like below, and when i debug i am going through all the code except Minstrel object methods, supposed object to fire methodsCode:package SampleAOP; public interface Quest { abstract HolyGrail embark(); }
MainClass.java
Code:package SampleAOP; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.FileSystemResource; public class MainClass { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub BeanFactory fact=new XmlBeanFactory(new FileSystemResource("\\SampleAOP.xml")); Minstrel m=(Minstrel) fact.getBean("minstrel"); Knight k=(Knight)fact.getBean("knight"); HolyGrail HG=k.embarkOnQuest(); HG.found(); } }
please some body help me
Regards
R


Reply With Quote