Announcement Announcement Module
Collapse
No announcement yet.
AOP advices not getting fired Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AOP advices not getting fired

    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)
    Code:
    <?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>
    HolyGrail.java
    Code:
    package SampleAOP;
    
    public class HolyGrail {
    
    public void found(){
    	System.out.println("The Grail is Found,Hahahaha.................");
    }
    }
    HolyGrailQuest.java
    Code:
    package SampleAOP;
    
    public class HolyGrailQuest implements Quest {
    
    	public HolyGrail embark() {
    		
    		return new HolyGrail();
    	}
    }
    Knight.java
    Code:
    package SampleAOP;
    public interface Knight {
    HolyGrail embarkOnQuest();
    }
    KnightOfTheRoundTable.java
    Code:
    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;
    	}
    
    
    }
    Minstrel.java
    Code:
    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");
    	}
    }
    Quest.java
    Code:
    package SampleAOP;
    
    public interface Quest {
    abstract HolyGrail embark();
    }
    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 methods
    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

  • #2
    Use an ApplicationContext instead of a BeanFactory. Why read this

    Comment


    • #3
      Thanks a lot. its working with Application Context.
      i will be going through that document

      Comment

      Working...
      X