java - Thymeleaf and Spring Boot not reading properties from localization files - Question marks appear instead of the localized string -


when attempting localize static string message displayed surrounded questionmarks "??"

e.g. ??ticket.type_en_us??

<p th:text="#{ticket.type}">blah</p> 
  • i using springboot 1.3.6.release
  • thymeleaf: 3.0.0.release
  • thymeleaf-spring4 artifact

i have configured basename of messages in application.properties

and contents of messages.properties , messages_en_us.properties is:

ticket.type=bugs!!!! 

config:

spring.messages.basename=messages 

output on startup:

2016-07-19 08:38:28.673 debug 5175 --- [ main] ationconfigembeddedwebapplicationcontext : using messagesource [org.springframework.context.support.resourcebundlemessagesource: basenames=[messages]]

i tried programatically using messageresource in code below. placed messages.properties file in same folder application.properties file. src/main/resources/

@configuration @componentscan("controller")  public class webconfig extends webmvcconfigureradapter implements applicationcontextaware{      private applicationcontext applicationcontext;      @autowired     private messagesource messagesource;      public void setapplicationcontext(applicationcontext applicationcontext) {         this.applicationcontext = applicationcontext;     }      @bean     public viewresolver viewresolver() {         thymeleafviewresolver resolver = new thymeleafviewresolver();         resolver.settemplateengine(templateengine());         resolver.setcharacterencoding("utf-8");         return resolver;     }      @bean     public templateengine templateengine() {         springtemplateengine engine = new springtemplateengine();         engine.settemplateresolver(templateresolver());         engine.setmessagesource(messagesource);         return engine;     }      @bean     public itemplateresolver templateresolver() {         springresourcetemplateresolver resolver = new springresourcetemplateresolver();         resolver.setapplicationcontext(applicationcontext);         resolver.setprefix("/web-inf/templates/");         resolver.settemplatemode(templatemode.html);         return resolver;     } } 

for completeness here application config (like others had exluse thymeleaf class):

@springbootapplication(exclude={org.springframework.boot.autoconfigure.thymeleaf.thymeleafautoconfiguration.class}) public class application {      public static void main(string[] args) {          applicationcontext ctx = springapplication.run(application.class, args);      }  } 

i have verified message bundles being loaded pring out contents on 1 of rest end-point calls:

@autowired     private messagesource messagesource;      @get     @produces("application/json")     public list<mydata> getdata() {         system.out.println("here 1 in conversions");          system.out.println(messagesource.getmessage("ticket.type", null, locale.us));          return getthedata();     } 

this prints out following know spring-boot loading resource bundles, thymeleaf not picking them somehow:

bugs!!!! 

here full html page, perhaps there issue it:

<html xmlns:th="http://www.thymeleaf.org"> <head>      <title>kitchen sink</title>     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>      <link href="http://cdn.jsdelivr.net/webjars/bootstrap/3.3.4/css/bootstrap.min.css"           th:href="@{/webjars/bootstrap/3.3.4/css/bootstrap.min.css}"           rel="stylesheet" media="screen" />      <script src="http://cdn.jsdelivr.net/webjars/jquery/2.1.4/jquery.min.js"             th:src="@{/webjars/jquery/2.1.4/jquery.min.js}"></script>      <link href="../static/css/mike.css"           th:href="@{css/mike.css}" rel="stylesheet" media="screen"/> </head>  <body> <div class="container">     <div class="jumbotron">          <h1>hello</h1>          <h2>welcome kitchen sink!</h2>          <p th:text="#{ticket.type}">blah</p>          <p th:text="#{test.type}">dssfgf</p>        </div>  </body>  </html> 

ok, figured out. @m.deinum poitning out should let spring-boot , thymeleaf supposed do.

i had set the:

engine.setmessagesource(messagesource); 

and add the:

@bean  

to 2 other functions. allowed messagesource passed engine , resolve properties correctly.

i update question above correct source people can use referene


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -