Set jpa utf-8 encoding in application.properties
Asked Answered
K

2

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.

Kamkama answered 25/10, 2016 at 22:19 Comment(1)
Truy this link docs.spring.io/spring-boot/docs/1.2.4.RELEASE/reference/html/…Athiste
M
5

if you are using spring boot, in application properties

spring.datasource.connectionProperties=useUnicode=true;characterEncoding=utf-8;
Mudpack answered 26/10, 2016 at 6:21 Comment(2)
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.4Anelace
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. Thanks.Benempt
C
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.

Champ answered 22/3, 2017 at 21:40 Comment(1)
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. Thanks.Benempt

© 2022 - 2024 — McMap. All rights reserved.