HTTP状态500 - servlet fitTrackerServlet的Servlet.init()引发异常 [英] HTTP Status 500 - Servlet.init() for servlet fitTrackerServlet threw exception

查看:225
本文介绍了HTTP状态500 - servlet fitTrackerServlet的Servlet.init()引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用Spring,我正在关注PluralSight的教程。运行第一个示例,我遇到标题中列出的错误。在我的控制台中,我收到这样的错误。我正在使用旧版本的依赖项来完成本课程。我已经确保密切关注这个教程,所以不确定我是否搞砸了某个地方或某些东西被弃用了。我正在使用 http:// localhost:8080 / FitnessTracker / greeting.html

This is my first time working with Spring and I am following the tutorial on PluralSight. Running the first example, I run into the error that is listed in the title. In my console, I get errors like these. I am using older versions of the dependencies to go through this course. I've made sure to follow the tutorial closely so not sure if I messed up somewhere or something is deprecated. I am using http://localhost:8080/FitnessTracker/greeting.html

SEVERE: Context initialization failed
java.lang.IllegalArgumentException
SEVERE: StandardWrapper.Throwable
java.lang.IllegalArgumentException
SEVERE: Allocate exception for servlet fitTrackerServlet
java.lang.IllegalArgumentException

HelloController.java

HelloController.java

package com.pluralsight.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HelloController {

    @RequestMapping(value = "/greeting")
    public String sayHello(Model model) {
        model.addAttribute("greeting", "Hello World");
        return "hello";
    }
}

servlet-config.xml

servlet-config.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"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        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-3.2.xsd">

    <mvc:annotation-driven />
    <context:component-scan base-package="com.pluralsight.controller" />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
    p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>

</beans>

hello.jsp

hello.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <h1>${greeting}</h1>
</body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet>
    <servlet-name>fitTrackerServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/config/servlet-config.xml</param-value>
    </init-param>
  </servlet>

  <servlet-mapping>
    <servlet-name>fitTrackerServlet</servlet-name>
    <url-pattern>*.html</url-pattern>
  </servlet-mapping>

  <display-name>Archetype Created Web Application</display-name>
</web-app>

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.pluralsight</groupId>
  <artifactId>FitnessTracker</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>FitnessTracker Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.2.0.RELEASE</version>
    </dependency>


    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
        <scope>provided</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>FitnessTracker</finalName>
  </build>
</project>


推荐答案

我在同一个PluralSight教程中遇到了同样的问题。我安装了Java 1.7和Java 1.8。该项目显然抛出了Java 1.8的异常。要纠正这种情况,您需要确保将Spring STS环境设置为使用Java 1.7。

I had the same problem with the same PluralSight tutorial. I had both Java 1.7 and Java 1.8 installed. The project apparently throws an exception with Java 1.8. To rectify this situation you need to ensure that your Spring STS environment is set to use Java 1.7.


  1. 右键单击项目并选择属性

  2. 属性对话框中,选择 Java编译器

  3. 在对话框的底部,选择用于配置已安装的JRE 的链接。

  4. 添加定义以指向JRE 1.7并选择此项作为默认。

  1. Right click on the project and select Properties.
  2. In the Properties dialog, select Java Compiler.
  3. At the bottom of the dialog, select the link to configure the Installed JREs.
  4. Add a definition to point to JRE 1.7 and select this as the default.

PluralSight教程现在适合我。我自己是Java和Spring MVC的初学者,所以我不确定这是否是解决问题的最佳方法。

The PluralSight tutorial now works for me. I am beginner to Java and Spring MVC myself so I am not sure if this was the best way to solve the problem.

这篇关于HTTP状态500 - servlet fitTrackerServlet的Servlet.init()引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆