我试图访问src/main/resources/XYZ/view文件夹中的xsd,其中XYZ/view文件夹由我和文件夹创建abc.xsd,我需要进行xml验证。如何访问src/main/resources /文件夹中的资源文件在Spring Boot
当我想尽我得到的结果为空时,
我曾尝试为,
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
以及我为获取资源或类加载程序而创建的更多路径。
最后我得到与XSD,
档案文件=新的文件(新使用ClassPathResource( “/ src目录/主/资源/ XYZ /查看/ abc.xsd”)的getPath()); Schema schema = factory.newSchema(file);
它正在工作,我想知道为什么其他两条路径会出错或为什么它不适合我并为其他人处理。 :(
还是有它我丢失
是的,它为我工作谢谢凯文 – tyro