Here's a snippet of a Spring bean:
@Component
public class Bean {
@Value("${bean.timeout:60}")
private Integer timeout;
// ...
}
Now I want to test this bean with a JUnit test. I'm therefore using the SpringJUnit4ClassRunner and the ContextConfiguration annotation.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class BeanTest {
@Autowired
private Bean bean;
// tests ...
@Configuration
public static class SpringConfiguration {
@Bean
public Bean bean() {
return new Bean();
}
}
}
Unfortunately the SpringJUnit4ClassRunner can't resolve the @Value
expression, even though a default value is supplied (a NumberFormatException is thrown). It seems that the runner isn't even able to parse the expression.
Is something missing in my test?