4

Не могу настроить чтение свойств из файла *.properties, используя Thymeleaf:

 <!DOCTYPE html>
    <html
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:th="http://www.thymeleaf.org/">
    <head>
    <title>Good Thymes Virtual Grocery</title>
    <link rel="stylesheet" type="text/css" media="all"
          href="../css/main-style.css"/>
    </head>
    <body>
    <p th:text="#{index.welcome}"></p>
   </body>
   </html>

Сами файлы свойств:

введите сюда описание изображения

И содержимое одного из них для примера:

index.welcome = Привет!
0

1 ответ 1

1

Используйте бин

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="messages"/>
</bean>

Как его использовать и далее по тексту примеры можно найти в примере на тему интернационализации.

Настройка интернационализации (i18n) / локализации (l10n) в Spring MVC

Мы создали resource properties для нашего приложения. Теперь мы должны объявить эти файлы в конфигурационом файле spring *-servlet.xml.

Будем использовать класс org.springframework.context.support.ReloadableResourceBundleMessageSource для определения resource properties.

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

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.