Announcement Announcement Module
Collapse
No announcement yet.
problem running simple aop! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem running simple aop!

    I am trying to run simple example of MethodBeforeAdvice. For some reason, method calls are not intercepted. Any suggestions? thanks in advance.

    Iitem is an interface. Book2 implements the interface.

    Code:
    my xml:
    <!-- simple bean implements Iitem--> 
    <bean id="book2" class="spring.test.Book2"/>    
    	
    <!-- The interceptor class --> 
    <bean id="before" class="spring.test.LogBefore"/>
    	
    <!--Proxying --> 
    <bean id="something" class="org.springframework.aop.framework.ProxyFactoryBean"> 
    <property name="proxyInterfaces"><value>spring.test.Iitem</value></property> 
    <property name="target"><ref local="book2"/></property> 
      <property name="interceptorNames"> 
      <list> 
      <value>before</value> 
      </list> 
      </property> 
     </bean> 
    
    code&#58;
    
    public class MainApplication &#123;
    
    public static void main&#40;String&#91;&#93; args&#41; &#123;
            ApplicationContext ctx =
              new FileSystemXmlApplicationContext&#40;"spring/test/test-servlet.xml"&#41;;
    
            Iitem book2 = &#40;Iitem&#41;ctx.getBean&#40;"book2"&#41;;
            //somethig should happen here!
           book2.setName&#40;"book1"&#41;;
           System.out.println&#40;book2.getName&#40;&#41;&#41;;
    	
    &#125;
    
    &#125;

  • #2
    Re: problem running simple aop!

    Originally posted by khalidhajsaleh
    Iitem book2 = (Iitem)ctx.getBean("book2");
    You have to retrieve the proxied bean, which is "something".

    Regards,
    Andreas

    Comment


    • #3
      Re:

      Thanks for the help!

      Iitem book2 = (Iitem)ctx.getBean("something");

      Comment

      Working...
      X