Meyyappan has posted 101 posts at DZone. View Full User Profile

Spring Interceptor Using Annotation Tutorial

  • submit to reddit

If you are using annotated Spring controllers, the only change that you need to do to the previous interceptor example is the configuration. In the Spring bean configuration file instead of using BeanNameUrlHandlerMapping or any other handler mapping use DefaultAnnotationHandlerMapping. The configuration file is shown below.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
	xmlns:xsi="" xmlns:p=""
	<bean id="viewResolver" class="org.springframework.web.servlet.view. InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
    <bean class="org.springframework.web.servlet.mvc.annotation. DefaultAnnotationHandlerMapping" p:interceptors-ref="loggerInterceptor" />
    <context:component-scan base-package="com.vaannila.web" />
    <bean id="loggerInterceptor" class="com.vaannila.interceptor.LoggerInterceptor" />
    <bean id="userService" class="com.vaannila.service.UserServiceImpl" />

You can download and try the example here.

Source :Download
War :Download
Published at DZone with permission of its author, Meyyappan Muthuraman.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



Dharmendra Deora replied on Sat, 2012/12/22 - 2:00am

nice example

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.