spring 的aop功能怎么不起作用。
大家帮我看看:
java 代码
- /**
- *
- */
- package com.dongyun.platform.test;
- /**
- * @author Administrator
- *
- */
- public class AppKwikEMart implements KwikEMart {
- /* (non-Javadoc)
- * @see com.dongyun.platform.test.KwikEMart#buySquishee(com.dongyun.platform.test.Customer)
- */
- public Squishee buySquishee(Customer customer) {
- System.out.println("give you");
- return new Squishee();
- }
- }
java 代码
- /**
- *
- */
- package com.dongyun.platform.test;
- import java.lang.reflect.Method;
- /**
- * @author Administrator
- *
- */
- public class WelcomeAdvice {
- /* (non-Javadoc)
- * @see org.springframework.aop.MethodBeforeAdvice#before(java.lang.reflect.Method, java.lang.Object[], java.lang.Object)
- */
- public void before(Method arg0, Object[] arg1, Object arg2)
- throws Throwable {
- System.out.println("Hello "+"!");
- }
- }
applicationContext.xml 代码
- <?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"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
- <aop:aspectj-autoproxy />
- <bean id="kwikEMartTarget"
- class="com.dongyun.platform.test.AppKwikEMart">
- </bean>
- <bean id="welcomeAdvice"
- class="com.dongyun.platform.test.WelcomeAdvice">
- </bean>
- <aop:config>
- <!-- 声明一个切入点。 -->
- <aop:aspect id="myAspect" ref="welcomeAdvice">
- <aop:pointcut id="apointcut"
- expression="execution(* com.dongyun.platform.test.AppKwikEMart.*(..))" />
- <aop:before method="before" pointcut-ref="apointcut" />
- </aop:aspect>
- </aop:config>
- </beans>
然后我在main函数里测试怎么不起作用。
java 代码
- package com.dongyun.platform.test;
- public class Main {
- public static void main(String[] args){
- ClassPathResource resource = new ClassPathResource("applicationContext.xml");
- BeanFactory factory = new XmlBeanFactory(resource);
- // AppKwikEMart app = (AppKwikEMart) factory.getBean("kwikEMartTarget");
- AppKwikEMart app = new AppKwikEMart();
- Customer cus = new Customer("chxkyy");
- app.buySquishee(cus);
- System.out.println("hello world!");
- }
- }
出来的结果只是:
give you
hello world!
为什么不打印Hello !呢?