2017-06-20 121 views
0

我試圖用簡單的Spring MVC項目,但我有例外的湯姆貓HTTP狀態500 - 爲的servlet MVC-調度Servlet.init()拋出異常

HTTP狀態500 - Servlet.init()進行的servlet MVC-調度拋出異常

類型異常報告

消息Servlet.init()進行的servlet MVC-調度拋出異常

描述服務器遇到阻止其完成此請求一個內部錯誤。

例外

javax.servlet.ServletException:Servlet.init()進行的servlet MVC-調度拋出異常 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) org.apache .catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java :502) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104) org.apache.coyote.AbstractProtocol $ A bstractConnectionHandler.process(AbstractProtocol.java:684) org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1519) org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run( NioEndpoint.java:1475) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util .threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745) 根本原因

org.springframework.beans.factory.BeanDefinitionStoreException:IOException異常解析XML來自ServletContext資源的文檔[/ WE B-INF/MVC-調度-servlet.xml中];嵌套異常是java.io.FileNotFoundException:無法打開ServletContext資源[/WEB-INF/mvc-dispatcher-servlet.xml] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344) org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181) org.springframework.beans.factory。 support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217) org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188) org.springframework.web.context.support.XmlWebApplic ationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125) org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94) org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129) org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:613) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:514) org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext (FrameworkServlet.java:668) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet。的java:634) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553) org.springframework.web.servlet .FrameworkServlet.initServletBean(FrameworkServlet.java:494) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache。 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java: 620) org .apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104) org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol .java:684) org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1519) org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1475 ) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745) 根源

java.io.FileNotFoundException:無法打開ServletContext的資源[/WEB-INF/mvc-dispatcher-servlet.xml] org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java :141) org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330) org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) org.springframework。 beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181) org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionRead er.java:217) org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188) org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125) 組織.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94) org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129) org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory (AbstractApplicationContext.java:613) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:514) org.springframe work.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet的。的java:682) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494) org.springframework.web.servlet .HttpServletBean.init(HttpServletBean.java:138) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) 有機apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter。 Java的:502) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104) org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:684) org.apache.tomcat.util .net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1519) org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1475) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor .java:1142) java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolEx ecutor.java:617) org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745) note注意完整的堆棧跟蹤的根本原因在Apache Tomcat/8.0.42日誌中可用。

我的web.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
     version="3.1"> 

    <servlet> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>WEB-INF/spring-servlet.xml</param-value> 
    </context-param> 

    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

</web-app> 

我的彈簧servlet.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:context="http://www.springframework.org/schema/context" 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 

    <mvc:annotation-driven/> 
    <context:component-scan base-package="controllers"/> 

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
     <property name="prefix" value="/"/> 
     <property name="suffix" value=".jsp"/> 
    </bean> 

    <mvc:default-servlet-handler /> 
</beans> 

我的控制器:

package controllers; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 

@Controller 
public class HomeController { 

    @RequestMapping(value = "/hello", method = RequestMethod.GET) 
    public String home() { 
     return "home"; 
    } 
} 

我的針對home.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %> 
<html> 
<head> 
    <title>Title</title> 
</head> 
<body> 
HELLO WORLD 
</body> 
</html> 
+0

日誌說, 「java.io.FileNotFoundException:無法打開ServletContext的資源[/WEB-INF/mvc-dispatcher-servlet.xml」。但是,您的web.xml指向spring-servlet.xml。檢查此文檔:http://docs.spring.io/spring-flex/docs/1.0.x/reference/html/ch02s02.html –

+0

我應該怎麼做才能解決它? –

+0

請參閱下面的答案。 –

回答

0

您應該提供調度servlet的位置(爲spring-servlet.xml)的init-param屬性。您是

web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
    http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
    version="3.1"> 

    //Dispatcher Servlet Config 
    <servlet> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/spring-servlet.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

</web-app> 
相關問題