是否有可能使用接线注释的Spring MVC的拦截? [英] Is it possible to wire a Spring MVC Interceptor using annotations?

查看:187
本文介绍了是否有可能使用接线注释的Spring MVC的拦截?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用接线注释的Spring MVC的拦截,如果是能不能有人为我提供了如何做到这一点的例子吗?

Is it possible to wire a Spring MVC Interceptor using annotations and if so could someone provide me with an example of how to do so?

通过借助注释,我指的是在XML配置尽可能做少线。例如在这个配置文件中,我发现在<一个href=\"http://www.vaannila.com/spring/spring-interceptors.html\">http://www.vaannila.com/spring/spring-interceptors.html;

By wire via annotation I am referring to doing as little in the XML configuration as possible. For example in this configuration file I found at http://www.vaannila.com/spring/spring-interceptors.html;

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" p:interceptors-ref="loggerInterceptor" />
<bean id="loggerInterceptor" class="com.vaannila.interceptor.LoggerInterceptor" />

怎么一点配置,你可以逃脱呢?我想一个 @Autowired 将消除需要显式声明在第2行的豆,但有可能得到与注释去掉1号线,以及?

How little configuration could you get away with there? I imagine an @Autowired would remove the need to explicitly declare the bean in line 2, but would it be possible to get rid of line 1 with an annotation as well?

推荐答案

据我所知,没有配置Spring MVC拦截器没有XML的方式都没有。

As far as I know, there are no ways to configure Spring MVC interceptors without XML at all.

不过,也有一些简化与 MVC 命名空间在Spring 3.0.x中的最新版本(不是Spring 3.0.0!):

However, there are some simplifications with mvc namespace in the latest versions of Spring 3.0.x (not Spring 3.0.0!):

<mvc:interceptors>
    <bean class="com.vaannila.interceptor.LoggerInterceptor" />
</mvc:interceptors>

参见:

  • MVC Simplifications in Spring 3.0

这篇关于是否有可能使用接线注释的Spring MVC的拦截?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆