在我的 Spring MVC 3.1 应用程序中,我认为我不能使用“”。为什么?因为我想应用一个拦截器all除“
<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>
因为我不希望拦截器应用于资源,并且(我认为)无法指定将拦截器应用于的映射路径除了这个和那个之外的一切.
所以我必须添加我自己的请求映射处理程序映射能够在其上指定拦截器,而不是全局的。因为this https://stackoverflow.com/a/3231197/843699 and this http://forum.springsource.org/showthread.php?81238-Conflict-between-lt-mvc-annotation-driven-gt-and-DefaultAnnotationHandlerMapping,看来我不能简单地定义我自己的请求映射处理程序映射同时保持元素!
所以...与一些帮助 https://stackoverflow.com/questions/3693397/howto-get-rid-of-mvcannotation-driven,我已经能够摆脱元素,现在几乎一切都运行良好。我将拦截器应用于除我的资源之外的所有内容。一切都运转良好,除了闪光瞄准镜!
@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
}
闪存映射为 NULL,我的模型不包含我的变量。当我尝试使用元素效果很好!所以我的问题是:我的上下文中缺少什么才能使闪存范围正常工作?
我还尝试将“org.springframework.web”设置为 DEBUG 日志记录级别,并且在重定向后没有任何与 FlashMap 或 FlashMapManager 相关的日志记录。看来肯定缺少一些必需的 bean。
以下是我的上下文文件中有趣的部分:
<!-- 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" />
闪光瞄准镜需要什么才能正常工作?
UPDATE:请参阅我的解决方案答案...实际上没有丢失任何内容。只是会话无法正常工作,我找到了一种让它工作的方法。