spring mvc import resource路径问题【最简单的却也是最致命的】
生活随笔
收集整理的這篇文章主要介紹了
spring mvc import resource路径问题【最简单的却也是最致命的】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在import resource 路徑中有兩種寫法
一種classpath,一種classpath*
那么這兩種有什么區別呢?
1.**classpath:**只會到你的class路徑中查找找文件;
2.**calsspath*😗*不僅包含class路徑,還包括jar文件中(class路徑)進行查找,***classpath*😗**對于多module的項目比較重要
但往往我們導入一個新的項目設置好路徑后,還會報出Cannot resolve file 'applicationContext.xml’
運行localhost:8080時,會報出:
Stacktrace:org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:584)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)javax.servlet.http.HttpServlet.service(HttpServlet.java:742)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)Root Causejavax.servlet.ServletException: Servlet.init() for servlet [SpringMVC] threw exceptionorg.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:742)org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:712)org.apache.jsp.index_jsp._jspService(index_jsp.java:113)org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)javax.servlet.http.HttpServlet.service(HttpServlet.java:742)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)javax.servlet.http.HttpServlet.service(HttpServlet.java:742)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)Root Causeorg.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring-mvc.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring-mvc.xml] cannot be opened because it does not existorg.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:343)org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:223)org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:194)org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:620)org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:521)org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:676)org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:642)org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:690)org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:558)org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:499)org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:172)javax.servlet.GenericServlet.init(GenericServlet.java:158)org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:742)org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:712)org.apache.jsp.index_jsp._jspService(index_jsp.java:113)org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)javax.servlet.http.HttpServlet.service(HttpServlet.java:742)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)javax.servlet.http.HttpServlet.service(HttpServlet.java:742)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)Root Causejava.io.FileNotFoundException: class path resource [spring-mvc.xml] cannot be opened because it does not existorg.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180)org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:223)org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:194)org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:620)org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:521)org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:676)org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:642)org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:690)org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:558)org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:499)org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:172)javax.servlet.GenericServlet.init(GenericServlet.java:158)org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:742)org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:712)org.apache.jsp.index_jsp._jspService(index_jsp.java:113)org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)javax.servlet.http.HttpServlet.service(HttpServlet.java:742)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)javax.servlet.http.HttpServlet.service(HttpServlet.java:742)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)檢查一陣路徑,發現沒有任何問題。其實這個問題是一個幾乎可以認為是一個不應該迷惑著我們的問題,也正如當局者迷,最簡單的確實最讓我們犯錯誤的。
resources文件屬性是否設置了
點擊后:正確的樣子
這樣路徑就不會出錯了。
總結
以上是生活随笔為你收集整理的spring mvc import resource路径问题【最简单的却也是最致命的】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何使用git上传本地文件到码云上【详细
- 下一篇: Dependency 'mysql:my