Resolve Spring @Value expression in JUnit tests Resolve Spring @Value expression in JUnit tests spring spring

Resolve Spring @Value expression in JUnit tests


Your test @Configuration class is missing an instance of PropertyPlaceholderConfigurer and that's why Spring does not know how to resolve those expressions; add a bean like the following to your SpringConfiguration class

@org.springframework.context.annotation.Beanpublic static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();    ppc.setIgnoreResourceNotFound(true);    return ppc;}

and move it to a separate class and use

@ContextConfiguration(classes=SpringConfiguration.class)

to be more specific when running your test.