Is there some way to tell IntelliJ that a particular .properties
file will be loaded into a project's environment? We use @PropertySource
annotations to load properties files, and in several places load override values from a file determined by an already-configured property, like so:
@Configuration
@PropertySource("classpath:com/example/package/db.properties")
@PropertySource("classpath:com/example/package/db.${db.instance}.properties")
public class DatabaseConfig {
private @Value("${db.someProperty}") String someDBProperty;
// ...
}
The problem is that within one of these indirectly referenced files, e.g. db.test.properties
, IntelliJ doesn't know if/how the properties file is referenced, so it can't tie any of the entries to their usages. (Bizarrely, some of the properties listed in these files are not greyed out to indicate 'Unused property', though even these give no results for a 'Find usages' search). There is no issue with directly named files, e.g. db.properties
above.
Is there some way to tell IntelliJ about these files short of creating additional dummy @Configuration
files that reference them?
This is how I do it:
Here an example when I am doing this in one of my projects: https://github.com/SFRJ/springpractice/blob/master/src/main/java/part3/PropertiesLoaderConfiguration.java
By the way, if you are using multiple property sources you can also do something like this:
@PropertySources({
@PropertySource("a.properties"),
@PropertySource("b.properties")
})