Last active
September 21, 2017 15:14
-
-
Save ju-la-berger/902abcd0a1292b529018f5a8cb95d642 to your computer and use it in GitHub Desktop.
Create Spring Environment from Resource (e.g. for unit testing)
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
package com.github.ju-la-berger; | |
import java.io.IOException; | |
import org.springframework.core.env.AbstractEnvironment; | |
import org.springframework.core.io.support.ResourcePropertySource; | |
public class EnvironmentFromResource extends AbstractEnvironment { | |
public EnvironmentFromResource(final String location) { | |
super(); | |
try { | |
final ResourcePropertySource propertySource = new ResourcePropertySource(location); | |
getPropertySources().addLast(propertySource); | |
} catch (final IOException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public EnvironmentFromResource() { | |
this("classpath:application.properties"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment