2

Spring ベースのプロジェクトに国際化を追加しようとしています。たくさんのガイドを試しましたが、うまくいきません。私はこれに長い間立ち往生しており、何が問題なのかを見つけることができません。まず、mvc-dispatcher-servlet.xml次のようになります。

?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.0.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

    <mvc:annotation-driven />
    <context:component-scan base-package="com.application" />

    <!-- Bean for the static resources (css,js) -->
    <mvc:resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources 
        in the /WEB-INF/views directory -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>


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

    <bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
        <property name="defaultLocale" value="en" />

    </bean>

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

私のmessages_en.propertiesファイルには以下が含まれています:

label.firstName=First Name
label.lastName=Last Name

また、私のJSPではプレースホルダーを使用しました:<spring:message code="label.firstName" /> これは私のプロジェクト構造です: ここに画像の説明を入力

どんな助けでも大歓迎です。

編集:souserのコメントのおかげで、国際化メッセージを含むリソースフォルダーが展開された戦争(Tomcat上)にないことがわかりました。存在する唯一のリソース フォルダーは、静的リソース (スクリーンショットのプロジェクト構造の /WebContent/resources/) を含むフォルダーです。

4

1 に答える 1