Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7772285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:51:14+00:00 2026-06-01T16:51:14+00:00

In my Spring MVC 3.1 application, I think I can’t use <mvc:annotation-driven />. Why?

  • 0

In my Spring MVC 3.1 application, I think I can’t use “<mvc:annotation-driven />”. Why? Because I want to apply an interceptor to all mappings except to the “<mvc:resources” elements. So I can’t use :

<mvc:annotation-driven />

<mvc:resources order="-10" mapping="/public/**" location="/public/" />
<mvc:resources order="-10" mapping="/favicon.ico" location="/public/favicon.ico" />
<mvc:resources order="-10" mapping="/robots.txt" location="/public/robots.txt" />
<mvc:resources order="-10" mapping="/humans.txt" location="/public/humans.txt" />

<mvc:interceptors>  
  <mvc:interceptor>
    <mvc:mapping path="/**"/>
    <bean class="com.my.Interceptor" />
  </mvc:interceptor>
</mvc:interceptors>

Because I don’t want the interceptor to apply to the resources and there is no way (I think) to specify a path for the mapping which would apply the interceptor to everything except this and that.

So I have to add my own RequestMappingHandlerMapping to be able to specify the interceptor on it, and not globally. Because of this and this, it seems I can’t simply define my own RequestMappingHandlerMapping while keeping the <mvc:annotation-driven /> element!

So… With some help, I’ve been able to get rid of the <mvc:annotation-driven /> element and pretty much everything works well now. I have my interceptor applied on everything but my resources. Everything works well, except the flash scope!

@RequestMapping(value="/test", method=RequestMethod.POST)
public String test(Model model, RedirectAttributes redirectAttrs) 
{
    redirectAttrs.addFlashAttribute("myKey", "my message");
    return "redirect:test2";
}

@RequestMapping(value="/test2")
public String test2(Model model, HttpServletRequest request) 
{
    Map<String, ?> map = RequestContextUtils.getInputFlashMap(request); // map is NULL
    System.out.println(model.containsAttribute("myKey")); // Prints FALSE
}

The flash map is NULL and my model doesn’t contain my variable. When I try with the <mvc:annotation-driven /> element it works well! So my question is: what is missing from my context to make the flash scope work?

I also did try to set “org.springframework.web” to a DEBUG logging level, and after the redirect there is nothing logged related to a FlashMap or FlashMapManager. It seems some required bean is definitely missing.

Here are the interesting parts of my context file:

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

<bean id="baseInterceptor" class="com.my.Interceptor" />

<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
    <property name="order" value="0" />
    <property name="interceptors">
        <list>
            <ref bean="conversionServiceExposingInterceptor" />
            <ref bean="baseInterceptor" />
        </list>
    </property>
</bean>

<bean id="myRequestMappingHandlerAdapter" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
    <property name="webBindingInitializer">
        <bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
            <property name="conversionService" ref="conversionService" />
            <property name="validator" ref="validator" />
        </bean> 
    </property>
    <property name="messageConverters">
        <list>
            <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
            <bean class="org.springframework.http.converter.StringHttpMessageConverter" />
            <bean class="org.springframework.http.converter.FormHttpMessageConverter" />
            <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
        </list>
    </property>
</bean>

<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean" />
<bean id="conversionServiceExposingInterceptor" class="org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor">
    <constructor-arg ref="conversionService" />
</bean>

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="classpath:/messages/messages" />
    <property name="defaultEncoding" value="UTF-8" />
</bean>

<bean class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver"></bean>

<mvc:resources order="-10" mapping="/public/**" location="/public/" />
<mvc:resources order="-10" mapping="/favicon.ico" location="/public/favicon.ico" />
<mvc:resources order="-10" mapping="/robots.txt" location="/public/robots.txt" />
<mvc:resources order="-10" mapping="/humans.txt" location="/public/humans.txt" />

What is missing for the flash scope to work?

UPDATE : See my answer for the solution… Nothing was missing actually. Only the Session was not working correctly and I found a way to make it work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:51:16+00:00Added an answer on June 1, 2026 at 4:51 pm

    I finally found what was missing for the flash scope to work!

    In the action where I access the flash variables (on the page the redirect leads to), I have to use this:

    public String test2(Model model, HttpServletRequest request, HttpSession session)
    

    instead of this :

    public String test2(Model model, HttpServletRequest request)
    

    It seems that this makes the Session to work correctly and therefore makes the flash scope to work correctly too! Why? I don’t know…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Spring MVC application trying to use a rich domain model, with
I'm currently building a Spring MVC application. I was looking to use JSP pages
My spring mvc application is broken into modules. My services are in their own
In my Spring MVC application I am using DTO in the presentation layer in
I have a spring mvc application that I have broken up into separate maven
I'm using Spring's form tag library in a Spring MVC application that I am
I'm using itext to generate pdf in my spring mvc application. The pdf is
I have a Spring Web MVC application that I'd like to serve a large,
I'm building a Spring MVC web application with Tiles/JSP as the view technology. Previously
I'm building a MVC web application (using the Spring MVC framework), and I'm a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.