当前位置: 首页 > 知识库问答 >
问题:

HTTP状态500-Servlet.init()for servlet appServlet抛出异常

诸葛煜
2023-03-14

我想尝试一个简单的程序,但出现以下错误。我正在使用Eclipse Kelper和Tomcat 7.0。我尝试了很多东西,但都不管用。

HTTP Status 500 - Servlet.init() for servlet appServlet threw exception
type Exception report

message Servlet.init() for servlet appServlet threw exception

description The server encountered an internal error that prevented it from fulfilling this request.

exception 

javax.servlet.ServletException: Servlet.init() for servlet appServlet threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)


root cause 

java.lang.IllegalArgumentException
    org.springframework.asm.ClassReader.<init>(Unknown Source)
    org.springframework.asm.ClassReader.<init>(Unknown Source)
    org.springframework.asm.ClassReader.<init>(Unknown Source)
    org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:52)
    org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
    org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
    org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76)
    org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:298)
    org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:300)
    org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:300)
    org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:230)
    org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:153)
    org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:130)
    org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:285)
    org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:223)
    org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
    org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:652)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:600)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:666)
    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:519)
    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:460)
    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    javax.servlet.GenericServlet.init(GenericServlet.java:160)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)


note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs.

有源代码:

>

  • web.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    
    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>
    
    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    

    servlet-context.xml:

    ?
    

    有人能解释一下问题出在哪里吗?

  • 共有3个答案

    龚俭
    2023-03-14

    试试这个:servlet-context.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1"> 
      <dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1">
        <dep:moduleId>
          <dep:groupId>org.apache.geronimo.samples.jws</dep:groupId>
          <dep:artifactId>Calculator</dep:artifactId> 
          <dep:version>1.0</dep:version> 
          <dep:type>car</dep:type>
        </dep:moduleId>
        <dep:dependencies>
        </dep:dependencies>
      </dep:environment>
      <context-root>/jaxws-calculator-1.0</context-root>
      <service-ref> 
        <service-ref-name>services/Calculator</service-ref-name>
        <port> 
          <port-name>CalculatorPort</port-name>
          <protocol>http</protocol>
          <host>localhost</host> 
          <port>8080</port> 
          <uri>/jaxws-calculator/calculator</uri> 
        </port>
      </service-ref>
    </web-app>
    
    子车征
    2023-03-14

    Servlet。init()错误主要是由于spring MVC的Jar文件版本不匹配引起的,请右键单击项目查看所有库

    还要从lib文件夹中删除jar库。再次构建项目并运行它。

    辛健
    2023-03-14

    尝试此配置或相应地重命名配置:我更喜欢将servlet命名为“dispatcher”,将其上下文文件命名为dispatcher servlet。xml。这对我来说很好。

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/dispatcher-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
     <servlet-mapping>
      <servlet-name>dispatcher</servlet-name>
      <url-pattern>/</url-pattern>
     </servlet-mapping>
    
     类似资料: