diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/velocity/VelocityAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/velocity/VelocityAutoConfiguration.java index 7c08177f84..2e0d4a32ef 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/velocity/VelocityAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/velocity/VelocityAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -86,6 +86,7 @@ public class VelocityAutoConfiguration { factory.setResourceLoaderPath(this.properties.getResourceLoaderPath()); factory.setPreferFileSystemAccess(this.properties.isPreferFileSystemAccess()); Properties velocityProperties = new Properties(); + velocityProperties.setProperty("input.encoding", this.properties.getCharset()); velocityProperties.putAll(this.properties.getProperties()); factory.setVelocityProperties(velocityProperties); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/velocity/VelocityAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/velocity/VelocityAutoConfigurationTests.java index 974e127b92..916cfbe76c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/velocity/VelocityAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/velocity/VelocityAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -109,6 +109,13 @@ public class VelocityAutoConfigurationTests { assertThat(response.getContentType(), equalTo("application/json;charset=UTF-8")); } + @Test + public void customCharset() throws Exception { + registerAndRefreshContext("spring.velocity.charset:ISO-8859-1"); + assertThat(this.context.getBean(VelocityConfigurer.class).getVelocityEngine() + .getProperty("input.encoding"), equalTo((Object) "ISO-8859-1")); + } + @Test public void customPrefix() throws Exception { registerAndRefreshContext("spring.velocity.prefix:prefix/"); diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index c957bd1ffc..ed962fa320 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -187,7 +187,7 @@ content into your application; rather pick only the properties that you need. spring.velocity.allow-session-override=false spring.velocity.cache=true spring.velocity.check-template-location=true - spring.velocity.charset=UTF-8 + spring.velocity.charset=UTF-8 # charset for input and output encoding spring.velocity.content-type=text/html spring.velocity.date-tool-attribute= spring.velocity.expose-request-attributes=false