Menu
Spring > Spring Interceptors

Spring Interceptors

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.

01.<?xml version="1.0" encoding="UTF-8"?>
02.<beans xmlns="http://www.springframework.org/schema/beans"
03.    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
04.    xmlns:context="http://www.springframework.org/schema/context"
05.    xsi:schemaLocation="http://www.springframework.org/schema/beans
06.    http://www.springframework.org/schema/beans/spring-beans.xsd
07.    http://www.springframework.org/schema/context
08.    http://www.springframework.org/schema/context/spring-context.xsd">
09.     
10.    <bean id="viewResolver" class="org.springframework.web.servlet.view. InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
11.     
12.    <bean class="org.springframework.web.servlet.mvc.annotation. DefaultAnnotationHandlerMapping" p:interceptors-ref="loggerInterceptor" />
13.           
14.    <context:component-scan base-package="com.w3javaguide.web" />
15.     
16.    <bean id="loggerInterceptor" class="com.w3javaguide.interceptor.LoggerInterceptor" />
17.     
18.    <bean id="userService" class="com.w3javaguide.service.UserServiceImpl" />
19.         
20.</beans>

You can download and try the example here.

Source :Download
War :Download
Subscribe
Contact Us  |  Copyright 2012 w3javaguide.com