1

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.

Community
  • 1
  • 1
kot09
  • 987
  • 3
  • 10
  • 18
  • Truy this link http://docs.spring.io/spring-boot/docs/1.2.4.RELEASE/reference/html/common-application-properties.html – AchillesVan Oct 25 '16 at 22:42

2 Answers2

5

if you are using spring boot, in application properties

spring.datasource.connectionProperties=useUnicode=true;characterEncoding=utf-8;
kuhajeyan
  • 10,727
  • 10
  • 46
  • 71
  • 8
    Spring Boot (as from 1.4) doesn't have `spring.datasource.connectionProperties`. That is a property specific to the connection pool that you are using so it highly depends which one you use. If you're using the Tomcat connection pool, that must be `spring.datasource.tomcat.connection-properties` in 1.4 – Stephane Nicoll Oct 26 '16 at 08:04
  • Hi @StephaneNicoll, would you know about configuring `oracle.net.CONNECT_TIMEOUT` in SpringBoot? If you want it as a question, someone has already asked [here](https://stackoverflow.com/questions/46204317/how-to-set-oracle-db-connection-timeout-in-spring-boot-application). Thanks. – jumping_monkey Dec 16 '19 at 06:55
1

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.

AndreyK
  • 61
  • 6
  • Hi @AndreyK, would you know about configuring oracle.net.CONNECT_TIMEOUT in SpringBoot? If you want it as a question, someone has already asked [here](https://stackoverflow.com/questions/46204317/how-to-set-oracle-db-connection-timeout-in-spring-boot-application). Thanks. – jumping_monkey Dec 16 '19 at 06:56