我在applicationContext.xml里面配置了
  <bean id="testLog" class="log.MyLog"></bean> <!--将日志类注入到bean中。-->
         <aop:config>
              <aop:aspect id="b" ref="testLog"><!--调用日志类-->
              <aop:pointcut id="log" expression="execution(* action.*.*(..))"/><!--配置在action包下所有的类在调用之前都会被拦截-->
              <aop:before pointcut-ref="log" method="before"/><!--在log包下面所有的类的所有方法被调用之前都调用MyLog中的before方法-->
              <aop:after pointcut-ref="log" method="after"/><!--在log包下面所有的类的所有方法被调用之前都调用MyLog中的after方法-->
              </aop:aspect>
         </aop:config>我的log.MyLog里面的内容是:package log;import org.aspectj.lang.JoinPoint;public class MyLog {
// 在类里面写方法,方法名诗可以任意的。此处我用标准的before和after来表示 public void before(JoinPoint joinpoint) {
joinpoint.getArgs();// 此方法返回的是一个数组,数组中包括request以及ActionCofig等类对象
System.out.println("被拦截方法调用之前调用此方法,输出此语句"); } public void after() { System.out.println("被拦截方法调用之后调用此方法,输出此语句"); }
}启动程序不报错。
我想问的是:当我在进入一个action时,是否应该打印出  被拦截方法调用之前调用此方法,输出此语句
                                                    {执行我的方法}
                                                    被拦截方法调用之后调用此方法,输出此语句
为什么我的程序没有任何反应呢?

解决方案 »

  1.   

    你换成对service的aop试试。我看你的配置都没什么错
      

  2.   

    我测试了下,我的配置基本跟你一样。是可以的 <bean name="logManager" class="com.study.spring.aop.LogManagerImpl"></bean>

    <bean name="logTestService" class="com.study.spring.aop.service.impl.LogTestServiceImpl"></bean>

    <aop:config>
    <aop:aspect id="logAspect" ref="logManager">
    <aop:pointcut id="logAOP" expression="execution(* com.study.spring.aop.service.*.*(..))"/>
    <aop:before method="printLog" pointcut-ref="logAOP"/>
    <aop:after method="printLog" pointcut-ref="logAOP"/>
    </aop:aspect>
    </aop:config>
      

  3.   

    你使用这个看看,是基于注解的:
    http://download.csdn.net/detail/zuxianghuang/4138590