【发布时间】:2017-10-03 21:29:04
【问题描述】:
我正在尝试访问 src/main/resources/XYZ/view 文件夹中的 xsd,其中 XYZ/view 文件夹是我创建的,并且文件夹具有我需要进行 xml 验证的 abc.xsd。
当我每次都尝试访问 xsd 时,我得到的结果为 null,
我试过了,
1)
@Value(value = "classpath:XYZ/view/abc.xsd")
private static Resource dataStructureXSD;
InputStream is = dataStructureXSD.getInputStream();
Source schemaSource = new StreamSource(is);
Schema schema = factory.newSchema(schemaSource);
2)
Resource resource = new ClassPathResource("abc.xsd");
File file = resource.getFile();
以及我为获取资源或类加载器等所做的更多路径。
最后我得到了xsd,
文件 file = new File(new ClassPathResource("/src/main/resources/XYZ/view/abc.xsd").getPath()); Schema schema = factory.newSchema(file);
它正在工作,我想知道为什么其他两条路径会出错,或者为什么它对我不起作用而对其他人很好。 :(
或者还有其他我想念的好方法
【问题讨论】:
标签: java spring-boot jaxb