3

I'm deploying some spring-boot app to Swisscom AppCloud which uses a MariaDB service. The service gets automatically configured in my app using the CloudFoundry connectors and the connection works fine.

However: since I heavily use ZonedDateTime-Objects in my Java-Code, I also included in the pom.xml...

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-java8</artifactId>
    </dependency>

...to properly preserve the ZonedDateTimes in the database.

This works fine on my local MariaDB, when I add...

    ...?useLegacyDatetimeCode=false

...to the connect string (as described here: https://moelholm.com/2016/11/09/spring-boot-controlling-timezones-with-hibernate/ -> "BONUS TIP: Getting the Hibernate configuration to work with MariaDB / MySQL").

How can I add this flag (and maybe others, too) to the connection to the MariaDB service on Swisscom AppCloud?

Lost Carrier
  • 123
  • 1
  • 7

1 Answers1

5

If you use Spring on CloudFoundry in conjunction with a MariaDB binding, the datasource is automatically configured by this mechanism: https://docs.cloudfoundry.org/buildpacks/java/spring-service-bindings.html

This is powered by the Spring cloud connectors project, which you can customize to your needs.

I did not test it, but you should be able to set the driver properties as follows:

@Bean
public DataSource dataSource() {
    PoolConfig poolConfig = new PoolConfig(5, 30, 3000);
    ConnectionConfig connConfig = new ConnectionConfig("useLegacyDatetimeCode=false");
    DataSourceConfig dbConfig = new DataSourceConfig(poolConfig, connConfig);
    return connectionFactory().dataSource(dbConfig);
}