为什么adivce不能在基于Spring框架的项目中工作?

时间:2017-06-22 07:18:05

标签: java spring aop

我用它如下:

@Component    
@Aspect    
public class RecordActivity {

@Pointcut("execution(public void test.article.service.ArticleService.*(..))")    
public void addArticle(){};

@Around("addArticle()")    
public void addActivity(ProceedingJoinPoint joinPoint){

        System.out.println("------add an article-------");
        try {
            writer.write(object.getObject());
        } catch (IOException e1) {
            e1.printStackTrace();
            bufferWriter.closeResource();
            ServiceUtil.outOfError(response,"error!!!");
            return;
        }
        bufferWriter.closeResource();
        try {
            joinPoint.proceed(params);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

控制器

@Controller    
public class PublicHandler {

@RequestMapping("/addarticle")    
public void addArtcile( HttpServletRequest request,HttpServletResponse response,Article article){

    articleService.addArticle(article);
    ...
}

服务

@Service    
public class ArticleService {

    @Transactional(rollbackFor=Exception.class)
    public void addArticle(Article article){
             ...
             ...
   }
}

springDispatcherServlet-servlet.xml包含:

<context:component-scan base-package="test.aop"></context:component-scan>

<aop:aspectj-autoproxy proxy-target-class="true"/>

<mvc:annotation-driven  ></mvc:annotation-driven>

jar包包含:

aspectJ.1.7.4:
 aspectjrt.jar

 aspectjweaver.jar

com.springsource.org.aopalliance-1.0.0.jar

com.springsource.net.sf.cglib-2.2.0.jar

spring-aop-4.3.9.RELEASE.jar

这是一个运行于的webApplication:  服务器:tomcat7.0.78

JDK:1.7

在上面配置之后,它开始正常,没有抛出任何异常。我通过webbrowser访问了add-Article服务,它反馈了一个正常的结果,但是没有执行advice方法。    我做错了什么?

0 个答案:

没有答案