Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Spring Boot中,通过@Value和资源类型将测试资源(.xml文件)注入测试类_Java_Spring_Spring Boot_Annotations - Fatal编程技术网

Java 在Spring Boot中,通过@Value和资源类型将测试资源(.xml文件)注入测试类

Java 在Spring Boot中,通过@Value和资源类型将测试资源(.xml文件)注入测试类,java,spring,spring-boot,annotations,Java,Spring,Spring Boot,Annotations,我有一个product.xml文件,我想通过使用Spring的@Value注释轻松地“注入”到我的测试类中 @SpringBootTest @TestPropertySource(properties = { "test.file.product=product.xml" }) public class XmlToJsonParserTest { @Value("${test.file.product}") private Resource product; @A

我有一个
product.xml
文件,我想通过使用Spring的
@Value
注释轻松地“注入”到我的测试类中

@SpringBootTest
@TestPropertySource(properties = {
        "test.file.product=product.xml"
})
public class XmlToJsonParserTest {

  @Value("${test.file.product}")
  private Resource product;

  @Autowired
  private XmlToJsonParser xlToJsonParser;

  @Test
  public void shouldParseFromXml() throws IOException {
    JsonNode node = xmlToJsonParser.getNodeFromXML(product.getFile());
    assertThat(node).isNotNull();
  }
}
我的测试文件在
src/test/resources/product.xml下
我以前设法让它工作,但就是不知道我是怎么做的,或者那天我有什么设置


在这种情况下,
product
始终为
null

是否尝试将
test.file.product
添加到test/resource folderWithout
@RunWith的应用程序属性中(SpringRunner.class
基于Spring的注释不会起任何作用。@M.Deinum legend您是否尝试在test/resource FolderWith的应用程序属性中添加
test.file.product
(SpringRunner.class
基于Spring的注释不会起任何作用。@M.Deinum legend