0
votes

I am setting up my DataSource in a Spring Boot / Spring Cloud Connectors project running on Cloud Foundry using Tomcat JDBC Connection Pool and MariaDB JDBC driver like so:

@Configuration
@Profile("cloud")
public class MyDataSourceConfiguration extends AbstractCloudConfig {
    @Bean
    public DataSource dataSource() {
        Map<String, Object> dataSourceProperties = new HashMap<>();
        dataSourceProperties.put("initialSize", "4"); // OK
        dataSourceProperties.put("maxActive", "4");   // OK
        dataSourceProperties.put("maxWait", "2000");  // OK
        dataSourceProperties.put("connectionProperties",      
        "useUnicode=yes;characterEncoding=utf8;"); // ignored
        DataSourceConfig conf = new DataSourceConfig(dataSourceProperties);
        return connectionFactory().dataSource(conf);
    }
}

For some reason only the properties referring to the pool size and maxWait but not the connectionProperties are getting picked up by the DataSource bean - see the log output:

maxActive=4; initialSize=4; maxWait=2000; connectionProperties=null

Any hints ?

Note: Trying to set the connectionProperties via Spring's ConnectionConfig class didn't work either.

2

2 Answers

2
votes

Try using the form of DataSourceConfig that takes separate PoolConfig and ConnectionConfig beans, like this:

@Bean
public DataSource dataSource() {
    PoolConfig poolConfig = new PoolConfig(4, 4, 2000);
    ConnectionConfig connectionConfig = new ConnectionConfig("useUnicode=yes;characterEncoding=utf8;");
    DataSourceConfig dbConfig = new DataSourceConfig(poolConfig, connectionConfig);
    return connectionFactory().dataSource(dbConfig);
}
0
votes

Try the following:

Replace

connProperties.put("connectionProperties", "useUnicode=yes;characterEncoding=utf8;");

with

connProperties.put("connectionProperties", "useUnicode=yes;characterEncoding=UTF-8;");

Alternately, you can also specify the following property directly in application.properties

spring.datasource.connectionProperties=useUnicode=true;characterEncoding=utf-8;