You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I am trying to test a subset of a SpringBoot app with JUnit. As stated in the documentation (here), we should be able to use ConfigFileApplicationContextInitializer.
In a JUnit test-case, I am trying to inject a some @Value properties from a application-dev.yml file (e.g. @Value("${my.pojo.name}") String name;). But these values are not injected (I've got the String "${my.pojo.name}" injected) when using ConfigFileApplicationContextInitializer and the annotation @ContextConfiguration while it seems to work when using @SpringApplicationConfiguration with a SpringApplication.
Context
Given a configuration class and a JUnit class:
There's no PropertySourcesPlaceholderConfigurer in your test configuration so the placeholder remains unresolved. You need to add some configuration that publishes one as a bean. If you use @SpringApplicationConfiguration then one will typically be auto-configured for you.
Hi,
I am trying to test a subset of a SpringBoot app with JUnit. As stated in the documentation (here), we should be able to use
ConfigFileApplicationContextInitializer
.In a JUnit test-case, I am trying to inject a some
@Value
properties from aapplication-dev.yml
file (e.g.@Value("${my.pojo.name}") String name;
). But these values are not injected (I've got the String"${my.pojo.name}"
injected) when usingConfigFileApplicationContextInitializer
and the annotation@ContextConfiguration
while it seems to work when using@SpringApplicationConfiguration
with a SpringApplication.Context
Given a configuration class and a JUnit class:
and a
application-dev.yml
:Obtained:
PojoConfiguration.name
has the value${my.pojo.name}
Expected:
PojoConfiguration.name
has the value defined in theapplication-dev.yml
You can reproduce the issue with the demo.tar.gz in attachment.
I've tested with SpringBoot version 1.2.7.RELEASE and 1.3.5.RELEASE.
It looks like other people have this issue (here)
Thanks in advance,
Cédric.
demo.tar.gz
The text was updated successfully, but these errors were encountered: