我有一个带有@Value注释的类
public class ServiceImpl {
@Value("${timeout}")
private long timeout;
...
}
和单元测试
@UnitTest
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:test/service-test-spring.xml")
@TestPropertySource("classpath:test/service-test.properties")
public class ServiceTest {
...
}
与上下文
<bean id="service" class="ServiceImpl"/>
运行测试时,由于以下异常而无法创建上下文:
Failed to convert value of type [java.lang.String] to required type [long]; nested exception is java.lang.NumberFormatException: For input string: "${timeout}"
它想以某种方式解析键,而不是从propertiesfile中解析属性:
timeout=18000
建议如何解决此问题。