I don't know that there's a good name for this technique, but it's basically what's required when you need to have local database credentials that differ from other developers in a team, and also can't be committed to version control. In React and Vue this feature is called .env.local.

When you need this in Spring, you need to know the following:

  • You can have multiple profiles.
  • But you'll need to end up gitignoring a file pattern at some point anyway.
  • Your 'mainstream' config file is likely stored under your project tree at src/main/resources/application.properties.
  • The default search path for Spring is:
    • file:./config/
    • file:./
    • classpath:/config/
    • classpath:/
  • file:. means the real root of your project, i.e. where your .git directory is, pom.xml, etc.
  • classpath:/ means src/main/resources, broadly speaking.

From this we can reason that the path of least resistance is to add a gitignore rule /config/ (the leading slash is important), and store your custom configuration in config/application.properties in the project root. Of course the more sophisticated way would be to use actual profiles, but this has the benefit of not needing any IDE configuration.

Note that this tends to work on a MERGE basis, rather than a simple basis where you use one config OR another config.

For instance, imagine that the standard application.properties as used by the team contains these lines:

logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG
logging.level.org.springframework.jdbc.core.StatementCreatorUtils=TRACE

Now imagine you have a similar set of lines in your own config/application.properties file:

logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG
logging.level.org.springframework.jdbc.core.StatementCreatorUtils=TRACE

The root logger for the application is at INFO level. You won't be able to silence these logs just by commenting out the lines in your own file. Because that will mean that the previous configuration remains, as it wasn't overridden by any more specific rule from your personal configuration. You need to explicitly override the log level for these classes:

logging.level.org.springframework.jdbc.core.JdbcTemplate=INFO
logging.level.org.springframework.jdbc.core.StatementCreatorUtils=INFO

To set the root logging level, use:

logging.level.root=DEBUG

Do not attempt to use the "short cut" logging.level., this will not work.