Got bad characters in scheduled tasks


April 2019


9 time


I use Spring (4.2.9.RELEASE) for a website. It uses Quartz-Scheduler (2.2.1) to run a scheduled task and this task needs to retrieve Chinese strings by using MessageSource. Here is some declaration:

<bean id="messageSource" class=""> 
    <property name="cacheSeconds" value="5" />
    <property name="basenames">
    <property name="defaultEncoding" value="UTF-8" />


The program for the scheduled task has this declaration:

private MessageSource messageSource;

When the task program runs, it retrieves i18n strings the following way:

Locale locale = LocaleUtils.toLocale(lang); 
String msg = messageSource.getMessage("label.message.alert", new Object[]{}, locale);

The "lang" is a string. If it is zh_TW for Chinese, the string retrieved is bad characters:


However, if the lang is en_US or es_MX, the retrieved strings look just right. How to fix this issue?

P.S. #1 My site uses JSP for page content. On a JSP page, the following shows English, Spanish, and Chinese characters correctly:

<spring:message code="label.message.alert"/>

Only the scheduled program has this issue.

I have three properties files having the i18n strings:

Inside each property file, there is a string similar to the following for each language:

label.message.alert=You've got messages.

In the, I have the following line:


P.S. #2 An interesting observation. Inside a web controller, I did the following:

private MessageSource messageSource;


Locale locale = LocaleUtils.toLocale("zh_TW"); 
String msg = messageSource.getMessage("label.message.alert", new Object[]{}, locale);

The retrieved Chinese string displays correctly.

0 answers