Announcement Announcement Module
Collapse
No announcement yet.
PropertySourcesPropertyResolver resolution order Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PropertySourcesPropertyResolver resolution order

    Following the Maven conventions, I have two database.properties files: one in src/main/resources/META-INF/spring/ (for the "main" classpath) and another in src/test/resources/META-INF/spring/ (for the test classpath).

    When I run a JUnit test, Spring is finding both files, and resolving property values from the "main" file and not from the file in the test classpath:

    Code:
    PropertySourcesPlaceholderConfigurer - Loading properties file from file [/Users/dserodio/Projetos/vulcano/rest-api/target/test-classes/META-INF/spring/database.properties]
    PropertySourcesPlaceholderConfigurer - Loading properties file from file [/Users/dserodio/Projetos/vulcano/rest-api/target/test-classes/META-INF/spring/email.properties]
    PropertySourcesPlaceholderConfigurer - Loading properties file from file [/Users/dserodio/Projetos/vulcano/rest-api/target/classes/META-INF/spring/database.properties]
    PropertySourcesPlaceholderConfigurer - Loading properties file from file [/Users/dserodio/Projetos/vulcano/rest-api/target/classes/META-INF/spring/email.properties]
    MutablePropertySources - Adding [localProperties] PropertySource with lowest search precedence
    PropertySourcesPropertyResolver - Searching for key 'database.driverClassName' in [environmentProperties]
    PropertySourcesPropertyResolver - Searching for key 'database.driverClassName' in [systemProperties]
    PropertySourcesPropertyResolver - Searching for key 'database.driverClassName' in [systemEnvironment]
    PropertySourcesPropertyResolver - Could not find key 'database.driverClassName' in any property source. Returning [null]
    PropertySourcesPropertyResolver - Searching for key 'database.driverClassName' in [localProperties]
    PropertySourcesPropertyResolver - Found key 'database.driverClassName' in [localProperties] with type [String] and value 'org.postgresql.Driver'
    org.postgresql.Driver is my production database, Spring should be resolving the database.driverClassName property as org.h2.Driver instead.

    From the log snippet above, you can see that the 'test-classes' is before 'classes' in the classpath. Shouldn't Spring use the value from the first file (ie, the test properties)? I'm using Spring 3.1.1.
Working...
X