Skip to content

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

I have the following Spring configuration[0].name=Some System[0].datasource.driverclassname=oracle.jdbc.OracleDriver[0].datasource.url=jdbc:oracle:thin:@foo:1521/bar[0].datasource.username=username[0].datasource.password=password

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

public class SystemConfig {
    public static class ConfiguredSystem {
        private final DataSourceProperties datasource = new DataSourceProperties();
        private String name;

        public JdbcTemplate getTemplate() {
            return new JdbcTemplate(datasource.initializeDataSourceBuilder().build());

    private final List<ConfiguredSystem> systems = new ArrayList<>();
    public List<ConfiguredSystem> allSystems() {
        return Collections.unmodifiableList(tradingSystems);

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

I am trying to move the password line into it’s own file, and keep the other properties in the main file.[0].datasource.password=password

I run with


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



Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (the profiles secret are currently active).
 | o.s.b.d.LoggingFailureAnalysisReporter [main]

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),[0]... across different files?



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

  • Creating a db.password property in the
  • Use ${db.password} in
9 People found this is helpful