2016-02-13 55 views
0

將我的Spring Boot版本升級到最新版本時出現小問題。我的message.properties沒有被檢測到,並且國際化沒有被加載,但是當我在版本1.3.0.RC1上運行時,一切正常,我的信息加載。我沒有改變application.properties的內容或消息本身的位置。我在這個主題上做了大量的搜索,並且從來沒有找到答案。我當前的application.properties如下所示:升級到最新版本時彈簧啓動國際化不起作用

spring.thymeleaf.cache=false 
server.session.cookie.http-only=true 
spring.resources.cache-period=0 
spring.application.name=Cardinal 
spring.messages.basename=internationalization/base 
spring.mvc.locale=sv_SE 
spring.messages.fallback-to-system-locale=true 
spring.messages.encoding=UTF-8 
server.tomcat.uri-encoding=UTF-8 
spring.http.encoding.charset=UTF-8 
spring.thymeleaf.mode=HTML5 
spring.thymeleaf.encoding=UTF-8 

如您所見,它們位於名爲internationalization的文件夾中,並且該文件具有base的前綴。我不知道該怎麼做,並非常感謝你的幫助。祝你有一個美好的一天同修,並且可能代碼永遠對你有利。

+2

您是否依賴MessageSource的自動配置?如果是這樣,現在必須啓用一個名爲'messages.properties'的文件來啓用自動配置。我找不到這方面的發行說明,但我從這裏的其他問題回憶起這個問題。如果您只有像「messages_sv.properties」這樣的特定於語言環境的文件,那麼您必須創建默認文件。 – dunni

+1

在發佈公告中提到:https://spring.io/blog/2016/01/22/spring-boot-1-3-2-released。默認的messages.properties作爲你沒有特定翻譯的地區的任何人的回退總是一個好主意 –

+0

啊哈,我明白了。我會測試這個,並且非常感謝你們。 –

回答

0

我設法在這個博客帖子https://spring.io/blog/2016/01/22/spring-boot-1-3-2-released和@Andy威爾金森我的消息組態提及具有默認messages.properties作爲後備解決這個問題是這樣的:

messages.properties:

index.page.title=Welcome 
page.brand=Cardinal 
signin.header=Please sign in 
signin.email.placeholder=Email 
signin.password.placeholder=Password 
signin.button.text=Sign in 
forgot.password.link.text=Forgot password 
rememberme.checkbox.text=Remember me 
navbar.header.loginbutton.text=Sign in 

messages_sv.properties:

index.page.title=Välkommem 
page.brand=Cardinal 
signin.header=Vänligen logga in 
signin.email.placeholder=E-postadress 
signin.password.placeholder=Lösenord 
signin.button.text=Logga in 
forgot.password.link.text=Glömt Lösenord? 
rememberme.checkbox.text=Kom ihåg mig 
navbar.header.loginbutton.text=Logga in 

和application.yml

server: 
    context-path: /Cardinal 
    session: 
    cookie: 
     http-only: true 
    tomcat: 
    uri-encoding: UTF-8 
    port: 8082 


spring: 
    thymeleaf: 
    cache: false 
    mode: HTML5 
    encoding: UTF-8 
    resources: 
    cache-period: 0 
    application: 
    name: Cardinal 
    messages: 
    basename: internationalization/messages 
    encoding: utf-8 
    mvc: 
    locale: sv_SE 
    http: 
    encoding: 
     charset: UTF-8 
debug: true 

希望這可以幫助有類似問題的人。