IDE下報IO錯:找不到springmvc.xml文件,F(xiàn)ileNotFoundException: class path resource [com/springmvcstudy/config/springmvc.xml] cannot be opened because it does not exist瀏覽器下報500錯誤,HTTP Status 500 - Servlet.init() for servlet springmvc threw exceptionIOException parsing XML document from class path resource [com/springmvcstudy/config/springmvc.xml]; nested exception is java.io.FileNotFoundException: class path resource?[com/springmvcstudy/config/springmvc.xml] cannot be opened because it does not exist但是我在web.xml中配置了contextConfigLocation,好像并沒有起作用。麻煩前輩們幫忙看下。springmvc項目結(jié)構(gòu)圖web.xml文件<?xml?version="1.0"?encoding="UTF-8"?>
<web-app?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
?????????xmlns="http://java.sun.com/xml/ns/javaee"
?????????xsi:schemaLocation="http://java.sun.com/xml/ns/javaee?http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
?????????id="WebApp_ID"?version="2.5">
<servlet><!--springmvc的前端控制器-->
????<servlet-name>springmvc</servlet-name>?<!--servlet名字-->
????<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>?<!--?servlet路徑-->
????<init-param>???????<!--?指定SpringMVC加載的配置文件(配置處理器映射器,適配器等),若沒有配置contextConfigLocation,SpringMVC的配置文件的默認路徑是/WEB-INF/springmvc-servlet.xml?-->
????????<param-name>contextConfigLocation</param-name>??<!---->
????????<param-value>classpath:com/springmvcstudy/config/springmvc.xml</param-value>??<!---->
????</init-param>
</servlet>
????<servlet-mapping>
????????<servlet-name>springmvc</servlet-name>????????<!--?設(shè)置所有以action結(jié)尾的請求進入SpringMVC?-->
????????<url-pattern>*.action</url-pattern>?<!--
????????1?/*.action
????????2?/??所有請求,都由dispatch-servlet解析,但是需要讀靜態(tài)資源設(shè)置放行。
????????3?/*??當(dāng)轉(zhuǎn)發(fā)jsp時,仍然會有dispatchservlet解析,無法根據(jù)url找到處理器handle
????????-->
????</servlet-mapping>
</web-app>springmvc.xml文件<?xml?version="1.0"?encoding="UTF-8"?>
<beans?xmlns="http://www.springframework.org/schema/beans"
???????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?xmlns:p="http://www.springframework.org/schema/p"
???????xmlns:context="http://www.springframework.org/schema/context"
???????xmlns:aop="http://www.springframework.org/schema/aop"
???????xmlns:mvc="http://www.springframework.org/schema/mvc"
???????xmlns:context="http://www.springframework.org/schema/context"
???????xmlns:tx="http://www.springframework.org/schema/tx"
???????xsi:schemaLocation="http://www.springframework.org/schema/beans?http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
????????http://www.springframework.org/schema/mvc?http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
?????????http://www.springframework.org/schema/aop?http://www.springframework.org/schema/aop/spring-aop.xsd
????????http://www.springframework.org/schema/tx?http://www.springframework.org/schema/tx/spring-tx.xsd
????????http://www.springframework.org/schema/context?http://www.springframework.org/schema/context/spring-context-4.0.xsd">
?????<!--配置controller掃描包-->
????<context:component-scan?base-package="com.springmvcstudy"?annotation-config="true"/>
????<!--配置處理器適配器,所有的處理器適配器都實現(xiàn)HandlerAdapter接口,-->
????<bean?class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
????<!--?處理器映射器?-->
????<!--?根據(jù)bean的name作為url,進行查找Handler?將action的url配置在bean的name中,需要在配置hendler時候指定beanname(就是url)?-->
????<bean?class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"?/>
????<!--配置處理器,將配置的handler在spring中進行加載-->
????<bean?name="/queryItems.action"?class="com.springmvcstudy.controller.ItemsController"/>
????<!--視圖解析器,解析jsp,默認使用jstl解析,所以classpath:下要用jstl的jar包-->
????<bean?class="org.springframework.web.servlet.view.InternalResourceViewResolver">
????????<property?name="viewClass"?value="org.springframework.web.servlet.view.JstlView"/>
????????<property?name="prefix"?value="/WEB-INF/jsp/"/>
????????<property?name="suffix"?value=".jsp"/>
????</bean>
</beans>這是controllerpackage?com.springmvcstudy.controller;
import?com.springmvcstudy.pojo.items;
import?org.springframework.web.servlet.ModelAndView;
import?org.springframework.web.servlet.mvc.Controller;
import?javax.servlet.http.HttpServletRequest;
import?javax.servlet.http.HttpServletResponse;
import?java.util.ArrayList;
import?java.util.List;
/**
?*?Created?by?huang?on?2017/11/20.
?*/
public?class?ItemsController?implements?Controller{
????public?ModelAndView?handleRequest(HttpServletRequest?request,?HttpServletResponse?response)?throws?Exception?{
????????//?conroller---service---impl---dao,調(diào)用service查找數(shù)據(jù)庫,此處使用靜態(tài)數(shù)據(jù)模擬
????????List<items>??itemses=new?ArrayList<items>();
????????//向list中添加假數(shù)據(jù)
????????items?items_1?=?new?items();
????????items_1.setName("聯(lián)想筆記本");
????????items_1.setPrice(6000f);
????????items_1.setDetail("ThinkPad?T430?聯(lián)想筆記本電腦!");
????????items?items_2?=?new?items();
????????items_2.setName("蘋果手機");
????????items_2.setPrice(5000f);
????????items_2.setDetail("iphone6蘋果手機!");
????????itemses.add(items_1);
????????itemses.add(items_2);
????//創(chuàng)建modelAndView準(zhǔn)備填充數(shù)據(jù)、設(shè)置視圖
????????ModelAndView?modelAndView=new?ModelAndView();
????????//填充數(shù)據(jù)
????????modelAndView.addObject("itemses2",itemses);
????????//?設(shè)置視圖,視圖就是渲染數(shù)據(jù)的媒介,如jsp
????????modelAndView.setViewName("/WEB-INF/jsp/items/itemsList.jsp");
????????return?modelAndView;
????}
}
springmvc.xml 無法讀取,訪問handler報錯500
Developer_Huang
2017-11-21 14:27:13