A, problem,

For example, the static/playctrl_map_code. XLSX file in the Resource directory fails to be obtained.

Second, the analysis

  1. On the second branch, classpathrecource.exists () returns false
  2. You can see that Null is returned here

  1. Static /playctrl_map_code. XLSX is loaded with the class loader of the current startup class.
ZhjkServerApplication.class.getClassLoader().getResource("static/playctrl_map_code.xlsx")
Copy the code
  1. Try to get the configuration file application.properties
ZhjkServerApplication.class.getClassLoader().getResource("application.properties")
Copy the code

  1. You can see that the configuration file is successfully obtained, and the obtained file path is in the compiled directory Target

  2. Check the target directory after compilation. The static path is missing. Locate the cause: compilation error

Third, solve

The cause of the problem has been found. It is a compilation problem, so I tried IDEA to recompile first, but it was obviously not successful.

  1. Check the POM.xml file and find that the resource default configuration is overwritten and the static directory configuration is missing

  1. Since we’ve abandoned the Filtering tag, the Resources configuration doesn’t make much sense anymore. Delete it and recompile it

  2. If IDEA compilation fails, it is recommended to manually compile using Maven, clean to clear target, install to install the local JAR to the local repository, and compile to compile.

mvn clean install compile
Copy the code
  1. Recompile target (target), run again, problem resolved