Announcement Announcement Module
Collapse
No announcement yet.
Simple AOP 2.0 XML Not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple AOP 2.0 XML Not working

    I am trying to learn the new AOP 2.0 XML syntax and for some reason I am missing something simple. Any help would be much appreciated.

    I want to add some around advice to this StandardStringUtils pojo. I had this working before with the old ProxyFactoryBean technique.

    When I run the HelloWorld main, I see:

    INFO: Loading XML bean definitions from class path resource [ApplicationContext.xml]
    em-esrever

    and thats it. Expect to see the around advice System.outs. What gives?

    Code:
    public interface StringUtils
    {
        String reverse(String value);
    }
    Code:
    public class StandardStringUtils implements StringUtils
    {
        public String reverse(String value)
        {
            if(null == value)
                return null;
    
            StringBuilder sb = new StringBuilder(value);
            return sb.reverse().toString();
        }
    }
    Code:
    public class PerformanceInterceptor
    {
        public Object doBasicProfiling(ProceedingJoinPoint call) throws Throwable
        {
            System.out.println("enter");
            Object o = call.proceed();
            System.out.println("done");
            return o;
        }
    }
    Code:
    public class HelloWorld
    {
        public static void main(String[] args)
        {
            XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("ApplicationContext.xml"));
            StringUtils utils = (StringUtils)factory.getBean("strUtils");
            System.out.println(utils.reverse("reverse-me"));
        }
    }
    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.5.xsd
    	                    http://www.springframework.org/schema/aop
    	                    http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    
        <aop:config>
           <aop:aspect id="profiling" ref="performance">
               <aop:around method="doBasicProfiling" pointcut="execution(* com.acme.utils.StringUtils.*(..))"/>
           </aop:aspect>
        </aop:config>
    
        <bean id="strUtils" class="com.acme.utils.StandardStringUtils"/>
        <bean id="performance" class="com.mapquest.sample.aop.interceptors.PerformanceInterceptor"/>
    </beans>

  • #2
    I suggest you read chapter 3 of the reference guide.

    Simple answer, use an ApplicationContext instead of a BeanFactory.

    Comment


    • #3
      Don't I feel stupid. Thanks Marten. I works now.

      Comment

      Working...
      X