我在学习spring in action 这本书的aop的例子时,为什么我编译没有报错,但是却没有执行我切入前后的方法?
xml配置代码如下:
<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" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id= "quest" class ="com.knight.HolyGrailQuest"> </bean> <bean id = "knight" class = "com.knight.KnightOfTheRoundTable"> <constructor-arg value='sotomi' /> <property name='quest' ref='quest'></property> </bean> <bean id = "minstrel" class = "com.knight.Minstrel"></bean> <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>
Minstrel类的方法如下:
public class Minstrel { private static final Logger Song = Logger.getLogger(Minstrel.class); public void singBefore(Knight knight){ Song.info("Knight is so brave!"); System.out.println("**********************before"); } public void singAfter(Knight knight){ Song.info("Knight did quest the grail!"); } }
测试main函数:
public class Test { public static void main(String args[]){ BeanFactory factory = new XmlBeanFactory(new FileSystemResource("bean.xml")); Knight knight = (Knight)factory.getBean("knight"); knight.embarkOnQuest(); } }
但是执行后没有打印结果,我哪里设置错误了么?