无法在Spring MVC中解析属性`paramName`

时间:2014-04-14 15:26:49

标签: java spring spring-mvc intellij-idea

我需要设置Spring MVC拦截器来捕获url参数language并相应地从.properties文件中获取数据。在Cannot resolve property中配置上下文时获取错误servlet-config.xml param名称:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <mvc:annotation-driven/>

    <mvc:resources mapping="/pdfs" location="pdfs"/>

    <context:component-scan base-package="com.ttu.cs.controller"/>

     <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basename="messages" />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />

    <bean id="LocaleResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" p:defaultLocale="en"/>

    <!-- Declare the Interceptor -->
    <mvc:interceptors>
        <bean class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
            <property name="paramName" value="language"/>
        </bean>

    </mvc:interceptors>
</beans>

2 个答案:

答案 0 :(得分:1)

我认为您打算使用org.springframework.web.servlet.i18n.LocaleChangeInterceptor而不是SessionLocaleResolver

<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    <property name="paramName" value="language"/>
</bean>

此类为HandlerInterceptor,并且具有paramName属性。

另一方面,

SessionLocaleResolver不是。

答案 1 :(得分:-1)

不确定您的期望,但SessionLocaleResolver没有这样的参数。也许你的意思是语言环境?