Lech Migdal
Lech Migdal

Reputation: 3984

Selecting parameters that should be used by Spring Boot when creating datasource in CF?

I have an app with Spring Boot (1.3.3.RELEASE)/Cloud (Brixton.M5) with MySQL deployed in Stackato CF, where I use CrudRepository. Unfortunately when the app starts, Spring Boot automatically configures DataSource using one of JDBC urls provided by Stackato, one that includes username and password, e.g.

jdbc:mysql://yourUser:[email protected]:3306/yourDB

Unfortunately apparently then Spring Boot assumes that everything before : is my host, while [email protected]:3306 is the port and in the end I get a nasty error.

Here is the output I see when the app starts:

[app.0] 2016-05-27T15:25:59.000Z: 2016-05-27 08:25:59.266 INFO 148 --- [ main] urceCloudServiceBeanFactoryPostProcessor : Auto-reconfiguring beans of type javax.sql.DataSource
[app.0] 2016-05-27T15:25:59.000Z: 2016-05-27 08:25:59.303 INFO 148 --- [ main] o.c.r.o.s.c.s.r.PooledDataSourceCreator : Found Tomcat high-performance connection pool on the classpath. Using it for DataSource connection pooling.
[app.0] 2016-05-27T15:25:59.000Z: 2016-05-27 08:25:59.345 INFO 148 --- [ main] urceCloudServiceBeanFactoryPostProcessor : Reconfigured bean dataSource into singleton service connector org.apache.tomcat.jdbc.pool.DataSource@6a98a805{ConnectionPool[defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=com.mysql.jdbc.Driver; maxActive=4; maxIdle=100; minIdle=0; initialSize=0; maxWait=30000; testOnBorrow=true; testOnReturn=false; timeBetweenEvictionRunsMillis=5000; numTestsPerEvictionRun=0; minEvictableIdleTimeMillis=60000; testWhileIdle=false; testOnConnect=false; password=********; url=jdbc:mysql://uk0pSal2suQS6:[email protected]:3306/dd558a39d22d44c059bb438d3b61941ef; username=null; validationQuery=/* ping */ SELECT 1; validationQueryTimeout=-1; validatorClassName=null; validationInterval=30000; accessToUnderlyingConnectionAllowed=true; removeAbandoned=false; removeAbandonedTimeout=60; logAba

and here is he error I get later:

[app.0] 2016-05-27T18:23:19.000Z: 2016-05-27 11:23:19.767 WARN 148 --- [io-44230-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 01S00
[app.0] 2016-05-27T18:23:19.000Z: 2016-05-27 11:23:19.767 ERROR 148 --- [io-44230-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : Illegal connection port value '[email protected]:3306'

Any suggestions how to go around this without dropping CrudTemplate? :)

I already tried setting correct spring.datasource.url with spring.datasource.username and spring.datasource.password in configuration files, but it seems that Spring Boot/Cloud ignores those on startup in favor of variables provided by the environment.

Upvotes: 1

Views: 426

Answers (1)

Lech Migdal
Lech Migdal

Reputation: 3984

The workaround that I've found is that I've followed the approach described at Binding to Data Services with Spring Boot in Cloud Foundry site, effectively disabling the auto-reconfiguration of the DataSource, which resulted in picking up connection parameters from the configuration file (vs from variables provided by the Stackato environment).

Upvotes: 3

Related Questions