ClassPathResource does not get the classpath

孤者浪人 提交于 2019-11-30 04:57:37

My guess is that the absolute path issue is because of the outputDirectory in the target of your maven POM . In my project the outputDirectory war/WEB-INF/classes and the it is from here the classes get executed . If I change it to some junk value , the class no longer gets executed .

So I believe the absolute path has to do something with the location of your .class files . Hope this helps .

There are two problems with new ClassPathResource("classpath:testMediaExif"):

  1. The classpath: prefix is only used in config files (e.g. XML files), and should not be used if you're using ClasspathResource directly.
  2. classpath:testMediaExif refers to a resource in the root of the classpath, not relative to the file in which you're making the reference.

Try this instead:

new ClasspathResource("testMediaExif", getClass())

or

new ClasspathResource("testMediaExif", MyClass.class)

These will construct a refernce to a resource called testMediaExif relative to MyClass.

One more thing: ClasspathResource.getFile() will only work in the resource really is a file. If it's packed in a JAR, then it won't work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!