【问题标题】:Cannot resolve property `paramName` in Spring MVC无法解析 Spring MVC 中的属性“paramName”
【发布时间】:2014-04-14 15:26:48
【问题描述】:

我需要设置 Spring MVC interseptors 来捕获 url 参数 language 并相应地从 .properties 文件中获取数据。在servlet-config.xml 中配置上下文时出现错误Cannot resolve propertyparamName:

<?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>

【问题讨论】:

  • 表示 org.springframework.web.servlet.i18n.SessionLocaleResolver 类没有名为 'paramName' 的属性

标签: java spring spring-mvc intellij-idea


【解决方案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 不是。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 2023-04-10
      • 2022-11-16
      • 2014-12-11
      • 1970-01-01
      • 2017-12-08
      相关资源
      最近更新 更多