【问题标题】:tomcat 8.0 failed to start while running a simple jersey program in eclipse在eclipse中运行简单的球衣程序时tomcat 8.0无法启动
【发布时间】:2017-10-09 14:41:17
【问题描述】:

我对这个问题感到沮丧。尝试了互联网上所有可能的解决方案,但仍然没有成功。

当我运行此代码时,tomcat 无法启动并且每次都失败。请帮忙

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container, 
     see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e194 -->

<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">
    <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.restapp.jerseyapp</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/jersey/*</url-pattern>
    </servlet-mapping>
</web-app>

代码:

package com.restapp.jerseyapp;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

/** Example resource class hosted at the URI path "/myresource"
 */
@Path("/hi")
public class MyResource {

    /** Method processing HTTP GET requests, producing "text/plain" MIME media
     * type.
     * @return String that will be send back as a response of type "text/plain".
     */
    @GET 
    @Produces("text/plain")
    public String getIt() {
        return "Hi there!";
    }
}

控制台输出

INFO: Starting Servlet Engine: Apache Tomcat/8.0.47
Oct 09, 2017 8:20:51 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/jerseyapp]]
    at java.util.concurrent.FutureTask.report(Unknown Source)
    at java.util.concurrent.FutureTask.get(Unknown Source)

【问题讨论】:

  • 能不能把 localhost 改成 localhost:8080,看看日志。
  • 您也应该检查(并发布)控制台视图的输出。
  • 将本地主机更改为 localhost:8080 但没有运气,更新了控制台错误。
  • @nitind -- 查看错误
  • 不要截断它。需要完整的日志输出。

标签: java eclipse tomcat jersey restful-architecture


【解决方案1】:

我也有同样的问题。我通过从本地 maven repo 中删除 jersey jars 解决了这个问题,然后重新安装了相同的 jars。

C:\Users\{user}\.m2\repository\com\sun\jersey

完成以上步骤后,请进行maven install。

【讨论】:

    猜你喜欢
    • 2021-02-10
    • 1970-01-01
    • 2015-11-12
    • 1970-01-01
    • 1970-01-01
    • 2012-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多