How do I configure encodings (UTF-8) for code executed by Quartz scheduled Jobs in Spring framework
- by Martin
I wonder how to configure Quartz scheduled job threads to reflect proper encoding. Code which otherwise executes fine within Springframework injection loaded webapps (java) will get encoding issues when run in threads scheduled by quartz.
Is there anyone who can help me out? All source is compiled using maven2 with source and file encodings configured as UTF-8.
In the quartz threads any string will have encoding errors if outside ISO 8859-1 characters:
Example config
<bean name="jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="example.ExampleJob" />
</bean>
<bean id="jobTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="jobDetail" />
<property name="startDelay" value="1000" />
<property name="repeatCount" value="0" />
<property name="repeatInterval" value="1" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="jobTrigger"/>
</list>
</property>
</bean>
Example implementation
public class ExampleJob extends QuartzJobBean {
private Log log = LogFactory.getLog(ExampleJob.class);
protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
log.info("ÅÄÖ");
log.info(Charset.defaultCharset());
}
}
Example output
2010-05-20 17:04:38,285 1342 INFO [QuartzScheduler_Worker-9] ExampleJob - vÖvÑvñ
2010-05-20 17:04:38,286 1343 INFO [QuartzScheduler_Worker-9] ExampleJob - UTF-8
The same lines of code executed within spring injected beans referenced by servlets in the web-container will output proper encoding.
What is it that make Quartz threads encoding dependent?