SSM framework exception problem

The problem that springmvc.xml cannot be loaded when the core controller is configured in the SSM framework web.xml


异常信息:
java.io.FileNotFoundException: class path resource [spring/springmvc.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:540)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:643)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:606)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:657)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:525)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:466)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1227)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1140)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1027)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5038)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5348)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase S t a r t C h i l d . c a l l ( C O n t a i n e r B a s e . j a v a : 1407 ) a t O r g . a p a c h e . c a t a l i n a . c O r e . C O n t a i n e r B a s e StartChild.call(ContainerBase.java:1397)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)


Project structure:
write picture description here
You can see a resource and a resources folder from the picture, the contents of both are the same (in order to reproduce the exception, the springmvc.xml in the resource folder has been changed), but the resources folder is my copy come in (the same location if the folder is created)

Look at the configuration in web.xml:
write picture description here
it stands to reason that there is no problem with the path of this file, but the configuration file of springmvc.xml cannot be loaded in life or death. I have found many ways to deal with it on the Internet, but there is no result, because this path seems to be There is no problem, including the structure in the workspace:
write picture description here
The locations of the two folders resource and resources are both above the root directory. It seems that the classpath can load the files here, but in fact there is no, but the difference Here, notice that there is a ".classpath" file in the picture above, open it:
write picture description here
in all the classpathentry tags, you can see that there is no reference to the resources folder in the .classpath file, but the existing resources folder It is a resource folder created with the Source Folder in eclipse (but the springmvc.xml configuration file is artificially removed from the resource folder at this time), so if it is not created in this way, there is no such <classpathentry kind="src" path="resource"/>line of code, then the classpath will default to Look for the path in the configuration under src, so the reason for this exception should be: the copied folder has the same effect as the folder created by Folder, and this type of folder will not be used as a resource folder when compiling The path is introduced into .classpath, so when loading through classpath: spring/springmvc.xml, this reference cannot be found in .classpath, so an error will be reported
. If there is an error, please correct me

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325561670&siteId=291194637