本文介绍了Spring 3 MVC @Controller with AOP拦截器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道为什么显然不可能使用带有注释的MVC控制器的AOP? (请参阅)。
我有一个@Controller,停止工作,只要我添加一个切入点。
问题不是拦截器没有被调用,而是@Controller简单停止工作(在日志中你可以看到,而不是映射的URL路径[/ xx]到处理程序'Yyy'你得到没有URL路径被识别)。

Anyone knows why apparently it is not possible to use AOP with annotated MVC Controllers? (see Post).I have a @Controller that stops working as soon as I add a pointcut to it.The problem is not that the interceptor is not being called, but rather the @Controller simply stops working (in the log you can see that instead of "Mapped URL path [/xx] onto handler 'Yyy'" you get a "no URL paths identified").

我知道有一种机制通过handlerMapping添加拦截器到控制器,但我的问题是特定于AOP拦截器。没有注释控制器只是pojos在Spring容器中作为任何其他pojo?有什么不同?为什么?

I know there is a mechanism for adding interceptors to controllers via the handlerMapping but my question is specific to AOP interceptors. Aren't annotated controllers just pojos in the Spring container as any other pojo? What is the difference? Why?

@Controller
@RequestMapping("/user")
public class RestTestImpl implements RestTest {
    @RequestMapping(value="/", method={RequestMethod.GET})
    public @ResponseBody String deleteUsers(String arg) {
        return "Xxxxx";
    }
}

在我的servlet-上下文中我有:

In my servlet-Context I have:

<context:component-scan base-package="org.xxx.yyy"></context:component-scan>
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    . . .
</bean>

一切都很棒。

但是当我添加:

    <aop:config>
        <aop:pointcut expression="execution(* org.xxx.*(..))" id="pc1"/>
        <aop:advisor advice-ref="hibernateInterceptor"  pointcut-ref="pc1" order="2" />
    </aop:config>

控制器停止作为控制器(没有错误,只是停止绑定到指定的URL) / p>

The controller stops being a controller (no errors, simply it stops binding to the specified URL)!

推荐答案

从:

已授予,此备注已隐藏: - )

Granted, this note is well hidden :-)

这篇关于Spring 3 MVC @Controller with AOP拦截器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 09:29