-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #505 from paveljandejsek/yamlPropertySourceRewrite
Rewritten yaml properties loading.
- Loading branch information
Showing
5 changed files
with
78 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...support-core/src/main/java/org/jbehavesupport/core/support/YamlPropertySourceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.jbehavesupport.core.support; | ||
|
||
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; | ||
import org.springframework.core.env.PropertiesPropertySource; | ||
import org.springframework.core.env.PropertySource; | ||
import org.springframework.core.io.support.EncodedResource; | ||
import org.springframework.core.io.support.PropertySourceFactory; | ||
|
||
import java.util.Properties; | ||
|
||
/** | ||
* The class {@link YamlPropertySourceFactory} allows to use YAML files as {@link org.springframework.core.env.Environment} properties sources. | ||
* <p> | ||
* Example usage in spring configuration: | ||
* <pre> | ||
* @Configuration | ||
* @PropertySource(value = "common-env.yml", factory = YamlPropertySourceFactory.class) | ||
* public class TestConfig { | ||
* } | ||
* </pre> | ||
* | ||
* To use variables please use standard spring ${} placeholder format see {@link PropertySource} for more information | ||
* For example: | ||
* <pre> | ||
* @PropertySource(value = {"common-env.yml", "${spring.profiles.active}.yml"}, factory = YamlPropertySourceFactory.class) | ||
* </pre> | ||
*/ | ||
public class YamlPropertySourceFactory implements PropertySourceFactory { | ||
|
||
@Override | ||
public PropertySource<?> createPropertySource(String name, EncodedResource encodedResource) { | ||
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); | ||
factory.setResources(encodedResource.getResource()); | ||
Properties properties = factory.getObject(); | ||
return new PropertiesPropertySource(name == null ? encodedResource.getResource().getFilename() : name, properties); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters