简体   繁体   中英

How to use Spring ClassPathResource: with classpath: or classpath*: and leading / or not?

I having file in the location

--src
  --> main
   --> config
    --> application
     --> context
      --> reference
       --> user
        --> user.xml

where

    --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();

But I getting FileNotFoundException , I tried with

Resource resource = new ClassPathResource("classpath:/application/context/references/user/user.xml");
File file = resource.getFile();

too, but still I getting the exception. Can someone help me to understand the working of ClassPathResource and right solution?

Use as below

Resource resource = new ClassPathResource("/application/context/references/user/user.xml");
File file = resource.getFile();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM