The first pit of getting started with spring, to solve the error class path resource [spring.xml] cannot be opened because it does not exist......

The following lines of code should be familiar to everyone, which is Spring's "Hello World".

 Then we may encounter [error] when running this main method: Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring.xml]; nested exception is java. io.FileNotFoundException: class path resource [spring.xml] cannot be opened because it does not exist...Like this:

It probably means that the configuration file spring.xml was not found. If you look carefully, spring.xml is in the resource directory. It seems that there is no problem.

Then expand and look at the target directory and find the problem. This is because in Idea, the compiler will only compile the .java files in src/main/java, which is the source code directory, into .class files and put them in the target directory. Others will not by default.

 Here we only need to copy the spring.xml file to target/classes/ to solve the problem

Then run it again, OK.

Guess you like

Origin blog.csdn.net/qq_42490860/article/details/129534982