Skip to content
Advertisement

Spring DataSource password in separate properties file causes “Failed to determine a suitable driver class”

I have the following Spring configuration

JavaScript

Which is configured into the following class (annotations are lombok and Spring).

JavaScript

This works just fine when all the properties are in one application.properties file. The application starts up properly.

I am trying to move the password line into it’s own application-secret.properties file, and keep the other properties in the main application.properties file.

JavaScript

I run with

JavaScript

However, when I do this I get the following error:

JavaScript

After putting a breakpoint in getTemplate, it seems the DataSourceProperties only contains the password and none of the other properties. I presume Spring cannot do list comprehension (for lack of a better term), myprefix.systems[0]... across different files?

Advertisement

Answer

This won’t answer why the initial solution (merging myprefix.systems[0].datasource.password) did not work, but you may solve your problem by:

  • Creating a db.password property in the application-secret.properties
  • Use ${db.password} in application.properties.
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement