Reputation: 1037
This is a followup question to the following:
JPA utf-8 characters not persisted
The answer (https://stackoverflow.com/a/32574280) worked for me. However, I would like to save those configurations in my application.properties file separate from the url configuration. What would be the name of those configurations?
I've tried:
connection.useUnicode=true
connection.characterEncoding=utf8
And then I set them in my Properties in my Configuration class:
properties.put("connection.useUnicode", env.getRequiredProperty("connection.useUnicode"));
properties.put("connection.characterEncoding", env.getRequiredProperty("connection.characterEncoding"));
But it isn't working.
Upvotes: 1
Views: 13014
Reputation: 61
I stumbled into the same problem. Namely, I need to enable connection encryption by setting Oracle specific properties while using Tomcat Data Source and Spring Boot.
Turns out the only way to do that with Spring Boot is to create a custom DataSource bean in the application configuration class.
There is no way to pass custom connection properties to the pool, Spring Boot doesn't allow that. I checked Spring Boot 1.4.1 and the current master version of Spring Boot.
If interested, take a look at DataSourceConfiguration.Tomcat class. The only properties it passes to the pool are the ones defined in DataSourceProperties class. The later doesn't have any fields allowing to pass custom properties, it supports only the predefined set of properties that are common for all datasources.
Upvotes: 1
Reputation: 11017
if you are using spring boot, in application properties
spring.datasource.connectionProperties=useUnicode=true;characterEncoding=utf-8;
Upvotes: 5