Reputation: 24616
I'm trying to define a spring data source url like so:
spring:
datasource:
url: "jdbc:${vcap.services.compose-for-mysql.credentials.uri}?useSSL=true&requireSSL=true&verifyServerCertificate=true"
username: ${vcap.services.compose-for-mysql.credentials.username}
password: ${vcap.services.compose-for-mysql.credentials.password}
driver-class-name: com.mysql.jdbc.Driver
Where vcap.services.compose-for-mysql.credentials.uri
is set to mysql://xxxx:[email protected]:28018/compose
.
I need the url to look like this:
jdbc:mysql://xxxx:[email protected]:28018/compose?useSSL=true&requireSSL=true&verifyServerCertificate=true
However, Spring doesn't appear to be able to handle this:
Could not get JDBC Connection; nested exception is java.sql.SQLException: Driver:com.mysql.jdbc.Driver@6c6efbc8 returned null for URL:jdbc:${vcap.services.compose-for-mysql.credentials.uri}?useSSL=true&requireSSL=true&verifyServerCertificate=true
Is there a way that I can construct the url using a yaml file, or do I need to use another approach such as xml configuration?
Update
I've tried:
url: ${'jdbc:'}${vcap.services.compose-for-mysql.credentials.uri}{'?useSSL=true&requireSSL=true&verifyServerCertificate=true'}
But get the error:
java.lang.IllegalArgumentException: URL must start with 'jdbc'
Also tried:
url: jdbc:${vcap.services.compose-for-mysql.credentials.uri}?useSSL=true&requireSSL=true&verifyServerCertificate=true
But get the error:
Driver:com.mysql.jdbc.Driver@567443ab returned null for URL:jdbc:${vcap.services.compose-for-mysql.credentials.uri}?useSSL=true&requireSSL=true&verifyServerCertificate=true
Upvotes: 6
Views: 5053
Reputation: 390
Just concatenate your env property with a string value
some:
property: ${envVar}abc
In your case
spring:
datasource:
url: jdbc:${vcap.services.compose-for-mysql.credentials.uri}?useSSL=true&requireSSL=true&verifyServerCertificate=true
Upvotes: 1