Support custom properties file formats in @TestPropertySource
Spring Framework 4.3 introduced the `PropertySourceFactory` SPI for use
with `@PropertySource` on `@Configuration` classes; however, prior to
this commit there was no mechanism to support custom properties file
formats in `@TestPropertySource` for integration tests.
This commit introduces support for configuring a custom
`PropertySourceFactory` via a new `factory` attribute in
`@TestPropertySource` in order to support custom file formats such as
JSON, YAML, etc.
For example, if you create a YamlPropertySourceFactory, you can use it
in integration tests as follows.
@SpringJUnitConfig
@TestPropertySource(locations = "/test.yaml", factory = YamlPropertySourceFactory.class)
class MyTestClass { /* ... /* }
If a custom factory is not specified, traditional `*.properties` and
`*.xml` based `java.util.Properties` file formats are supported, which
was the existing behavior.
Closes gh-30981
This commit is contained in:
5
spring-test/src/test/resources/org/springframework/test/context/env/repeatable/local.yaml
vendored
Normal file
5
spring-test/src/test/resources/org/springframework/test/context/env/repeatable/local.yaml
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
key1: local file
|
||||
environments:
|
||||
dev:
|
||||
url: https://dev.example.com
|
||||
name: Developer Setup
|
||||
7
spring-test/src/test/resources/org/springframework/test/context/env/test-properties.yaml
vendored
Normal file
7
spring-test/src/test/resources/org/springframework/test/context/env/test-properties.yaml
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
environments:
|
||||
dev:
|
||||
url: https://dev.example.com
|
||||
name: Developer Setup
|
||||
prod:
|
||||
url: https://prod.example.com
|
||||
name: My Cool App
|
||||
Reference in New Issue
Block a user