Java 球衣:com.sun.jersey.spi.inject.Errors$ErrorMessagesException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20376932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 01:29:41  来源:igfitidea点击:

Jersey: com.sun.jersey.spi.inject.Errors$ErrorMessagesException

javaweb-serviceshibernaterestmaven

提问by user3066027

i've got a problem using jersey (1.8), maven and hibernate.

我在使用 jersey (1.8)、maven 和 hibernate 时遇到了问题。

i get this error (the "full" log)

我收到此错误(“完整”日志)

        INFO: Scanning for root resource and provider classes in the packages:
      de.tum.fml.idp.backend.rest
    Dez 04, 2013 2:29:40 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
    INFO: Root resource classes found:
      class de.tum.fml.idp.backend.rest.PlayerWebService
      class de.tum.fml.idp.backend.rest.RestSample
    Dez 04, 2013 2:29:40 PM com.sun.jersey.api.core.ScanningResourceConfig init
    INFO: No provider classes found.
    Dez 04, 2013 2:29:41 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
    INFO: Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
    Dez 04, 2013 2:29:42 PM com.sun.jersey.spi.inject.Errors processErrorMessages
    SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
      SEVERE: Producing media type conflict. The resource methods public java.util.List de.tum.fml.idp.backend.rest.PlayerWebService.getPlayerIDs() and public de.tum.fml.idp.gamelog.backend.beans.Player de.tum.fml.idp.backend.rest.PlayerWebService.createUser() can produce the same media type
      SEVERE: Producing media type conflict. The resource methods public java.util.List de.tum.fml.idp.backend.rest.PlayerWebService.getPlayers() and public de.tum.fml.idp.gamelog.backend.beans.Player de.tum.fml.idp.backend.rest.PlayerWe
bService.createUser() can produce the same media type
    2013-12-04 14:29:42.010:WARN:/0.1-SNAPSHOT:unavailable
    com.sun.jersey.spi.inject.Errors$ErrorMessagesException
        at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
        at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
        at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)
        at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
        at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
        at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
        at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
        at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
        at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
        at javax.servlet.GenericServlet.init(GenericServlet.java:241)
        at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:477)
        at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:293)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:730)
        at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:254)
        at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1240)
        at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:689)
        at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:482)
        at org.eclipse.jetenter code herety.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
        at org.eclipse.jetty.server.Server.doStart(Server.java:281)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 

sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.codehaus.cargo.container.jetty.internal.JettyExecutorThread.run(JettyExecutorThread.java:69)
        2013-12-04 14:29:42.022:INFO:oejw.WebInfConfiguration:Extract jar:file:/C:/Users/Stefan/Dropbox/Studium/TUM/IDP/repo/backend/backend/target/cargo/configurations/jetty7x/cargocpc.war!/ to C:\Users\Stefan\AppData\Local\Temp\jetty-0.0.0.0-8080-cargocpc.war-_cargocpc-any-\webapp
        2013-12-04 14:29:42.052:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/cargocpc,file:/C:/Users/Stefan/AppData/Local/Temp/jetty-0.0.0.0-8080-cargocpc.war-_cargocpc-any-/webapp/},C:\Users\Stefan\Dropbox\Studium\TUM\IDP\repo\backend\backend\target\cargo\configurations\jetty7x\cargocpc.war
        2013-12-04 14:29:42.108:INFO:oejs.AbstractConnector:Started [email protected]:8080

and here is my used code:

这是我使用的代码:

package de.tum.fml.idp.backend.rest;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

import de.tum.fml.idp.backend.rest.interfaces.PlayerManagment;
import de.tum.fml.idp.gamelog.backend.beans.Player;
@Path("/players")
public class PlayerWebService implements PlayerManagment {

    @Override
    @GET
    public Player createUser() {
        // TODO Auto-generated method stub
        return new Player();
    }

    @Override
    @POST
    public Player updatePlayer(Player player) {
        // TODO Auto-generated method stub
        return new Player();
    }

    @Override
    @GET
    @Path("/getPlayer/{param}")
    public Player getPlayer(@PathParam("param") int id) {
        // TODO Auto-generated method stub
        Player bla = new Player();
        bla.setId(-1);
        return bla;
    }

    @Override
    @GET
    public List<Player> getPlayers() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    @GET
    public List<Integer> getPlayerIDs() {
        // TODO Auto-generated method stub
        return null;
    }



}

and the Player class.

和播放器类。

package de.tum.fml.idp.gamelog.backend.beans;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.xml.bind.annotation.XmlRootElement;

import org.hibernate.annotations.Entity;

//@XmlRootElement
public class Player {

//  @Id 
//  @GeneratedValue
    private int id; 

    private String name;

    private String password;

    Avatar avatar;

    private PlayerProperties properties; 

    private int tempId;

    private int availablePropertyPoints; 

    private int totalPropertyPoints;

//  @OneToMany
    private ArrayList<AchievedAchievment> achievments;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String string) {
        this.name = string;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Avatar getAvatar() {
        return avatar;
    }

    public void setAvatar(Avatar avatar) {
        this.avatar = avatar;
    }

    public PlayerProperties getProperties() {
        return properties;
    }

    public void setProperties(PlayerProperties properties) {
        this.properties = properties;
    }

    public int getTempId() {
        return tempId;
    }

    public void setTempId(int tempId) {
        this.tempId = tempId;
    }

    public int getAvailablePropertyPoints() {
        return availablePropertyPoints;
    }

    public void setAvailablePropertyPoints(int availablePropertyPoints) {
        this.availablePropertyPoints = availablePropertyPoints;
    }

    public int getTotalPropertyPoints() {
        return totalPropertyPoints;
    }

    public void setTotalPropertyPoints(int totalPropertyPoints) {
        this.totalPropertyPoints = totalPropertyPoints;
    }

    public List<AchievedAchievment> getAchievments() {
        if(achievments == null)
            achievments = new ArrayList<AchievedAchievment>();

        return achievments;
    }

    public void setAchievments(ArrayList<AchievedAchievment> achievments) {
        this.achievments = achievments;
    }

    public void addAchievment(AchievedAchievment aa1) {
        if(achievments == null)
            achievments = new ArrayList<AchievedAchievment>();

        if(aa1.getPlayer() != this)
            throw new RuntimeException("Player: Achievment was already given to   another user");
        else 
            achievments.add(aa1);

    }
}

has anyone an idea why this isn't working? tried already commenting almost everything out, several different maven dependencies, but it will not start working.

有谁知道为什么这不起作用?已经尝试将几乎所有内容都注释掉,几个不同的 maven 依赖项,但它不会开始工作。

"toy examples" are working fine... :-/

“玩具示例”工作正常......:-/

i hope you can help me,

我希望你可以帮助我,

kr,

克,

采纳答案by kapex

The error messages are telling you what is wrong (you have to look for lines starting with SEVERE):

错误消息告诉您出了什么问题(您必须查找以 开头的行SEVERE):

SEVERE: Producing media type conflict. The resource methods public java.util.List de.tum.fml.idp.backend.rest.PlayerWebService.getPlayerIDs() and public de.tum.fml.idp.gamelog.backend.beans.Player de.tum.fml.idp.backend.rest.PlayerWebService.createUser() can produce the same media type

SEVERE: Producing media type conflict. The resource methods public java.util.List de.tum.fml.idp.backend.rest.PlayerWebService.getPlayers() and public de.tum.fml.idp.gamelog.backend.beans.Player de.tum.fml.idp.backend.rest.PlayerWebService.createUser() can produce the same media type

严重:产生媒体类型冲突。资源方法 public java.util.List de.tum.fml.idp.backend.rest.PlayerWebService.getPlayerIDs() 和 public de.tum.fml.idp.gamelog.backend.beans.Player de.tum.fml.idp .backend.rest.PlayerWebService.createUser() 可以产生相同的媒体类型

严重:产生媒体类型冲突。资源方法 public java.util.List de.tum.fml.idp.backend.rest.PlayerWebService.getPlayers() 和 public de.tum.fml.idp.gamelog.backend.beans.Player de.tum.fml.idp .backend.rest.PlayerWebService.createUser() 可以产生相同的媒体类型

It means you have multiple GET endpoints for the same path (defined in the class' annotation @Path("/players")), producing the same media type:

这意味着您对同一路径(在类的注释中定义)有多个 GET 端点@Path("/players"),产生相同的媒体类型:

@GET
public List<Player> getPlayers()

@GET
public Player createUser()

@GET
public List<Integer> getPlayerIDs()

Jersey can't tell which one you want to call when sending a GET request to /players. You need to define separate paths for some of those endpoints.

Jersey 无法告诉您在向/players. 您需要为其中一些端点定义单独的路径。

If your intention actually was to let them have the same path, you would need to add @Producesannotations with different media types, so Jersey can choose the right method based on the Acceptheader. In case of request with a request body, you can also use the @Consumesannotation. Otherwise you need to add @Pathannotations or change the request types of your methods, to avoid this conflict.

如果您的意图实际上是让它们具有相同的路径,则需要添加@Produces具有不同媒体类型的注释,以便 Jersey 可以根据Accept标题选择正确的方法。如果请求带有请求正文,您也可以使用@Consumes注释。否则,您需要添加@Path注释或更改方法的请求类型,以避免这种冲突。