Spring ClassPathResource如何工作? [英] How Spring ClassPathResource is working?
本文介绍了Spring ClassPathResource如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在该位置有档案
--src
--> main
--> config
--> application
--> context
--> reference
--> user
--> user.xml
其中
--src
--> main
--> config
在类路径中。现在我尝试使用
is in the classpath. Now I am trying to access the file using
Resource resource = new ClassPathResource("classpath**:/application/context/references/user/user.xml");
File file = resource.getFile();
但我得到 FileNotFoundException
,我试过
Resource resource = new ClassPathResource("classpath:/application/context/references/user/user.xml");
File file = resource.getFile();
,但我仍然得到例外。有人可以帮我理解 ClassPathResource
和正确解决方案的工作吗?
too, but still I getting the exception. Can someone help me to understand the working of ClassPathResource
and right solution?
推荐答案
使用如下
Resource resource = new ClassPathResource("/application/context/references/user/user.xml");
File file = resource.getFile();
这篇关于Spring ClassPathResource如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文