@Service
public class TestService{
private String path;
public TestService(@Value("${test.path:}") String path) {
this.path = path;
}
}
...
TestService service = new TestService("testValue");
或使用reflectiontestutils设置值:
TestService service = new TestService();
ReflectionTestUtils.setField(service, "path", "somePath");
1条答案
按热度按时间ikfrs5lh1#
考虑到您不想设置spring(boot)测试,可以使用构造函数注入来注入value字段:
或使用reflectiontestutils设置值: