Closed ValdasK closed 3 years ago
Environment
should be able to read values from yaml files. We use it this way and it works well.
Could you please check it directly in your test class? Just inject Environment
bean to your test class, invoke environment.getProperty("...")
and compare the result with a value in field annotated with @Value("${zonky.test.database.postgres.docker.image}")
.
Something like this:
@RunWith(SpringRunner.class)
public class ConfigurationPropertiesIntegrationTest {
@Autowired
private Environment environment;
@Value("${zonky.test.database.postgres.docker.image}")
private String valueDockerImage;
@Test
public void testConfigurationProperties() throws Exception {
String envDockerImage = environment.getProperty("zonky.test.database.postgres.docker.image", "postgres:11-alpine");
// compare or print envDockerImage and valueDockerImage variables
}
}
Thanks for swift reply; it turns out that none of configs were actually parsed!
Added context initialize like
@ContextConfiguration(
initializers = ConfigDataApplicationContextInitializer.class,
classes = {...})
and it started to populate config values (and that made this setting work correctly).
It's really confusing what you have to add/what you can omit once you start customizing things...
If this sounds like reasonable thing to do; you can close issue.
Yes, of course, ConfigFileApplicationListener
must be registered properly. Otherwise it can't work.
Ok, I consider it solved and I'm closing the issue.
I am unable to change image which is used for tests when using Spring Boot 2.4.3 + YML configuration.
If I add
into
application.yml
, it get's ignored, and adding breakpoint inDockerPostgresDatabaseProvider
shows that
dockerImage
is still"postgres:11-alpine"
. I think this could be caused thatEnvironment
does not parse YML, and only works with.properties
? Would it not be possible to use@Value
to extract configurations instead?