Jersey:com.sun.jersey.spi.inject.Errors $ ErrorMessagesException [英] Jersey: com.sun.jersey.spi.inject.Errors$ErrorMessagesException

查看:155
本文介绍了Jersey:com.sun.jersey.spi.inject.Errors $ ErrorMessagesException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我得到这个错误(完整日志)

  INFO:扫描包中的根资源和提供者类:
de.tum.fml.idp.backend.rest
Dez 04,2013 2:29:40 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO:找到的根资源类:
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
信息:找不到提供者类。
Dez 04,2013 2:29:41 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO:启动Jersey应用程序,版本泽西岛:1.8 06/24/2011 12: 17 PM'
Dez 04,2013 2:29:42 PM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE:在资源和/或提供者类中检测到以下错误和警告:
SEVERE:产生媒体类型冲突。资源方法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()可以产生相同的媒体类型
SEVERE:产生媒体类型冲突。资源方法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()可以生成相同的媒体类型
2013-12-04 14:29:42.010:WARN:/0.1-SNAPSHOT:不可用
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.conta iner.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)$ or $
org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:293)
at org.eclipse.jetty。 util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
在org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:730)
在org.eclipse.jetty.servlet。 ServletContextHandler.startCont ext(ServletContextHandler.java:254)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1240)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(
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(
在org.eclipse.jetty.server.handler.HandlerCollection.doStart(
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart( HandlerCollection.java:229)
在org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
在org.eclipse.jetty.server.handler。 HandlerWrapper.doStart(HandlerWrapper.java:95)
位于org.eclipse.jetty.server.Server.doStart(Server.java:281)
位于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.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!/到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 oejwWebAppContext {/ cargocpc,file:/ C:/ Users / Stefan / AppData / Local / Temp /码头-0.0.0.0-8080-cargocpc.war-_cargocpc-任何 - / web应用/},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 SelectChannelConnector@0.0.0.0:8080

以下是我用过的代码:

  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;

导入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自动生成的方法存根
返回新的Player();
}

@Override
@POST
public Player updatePlayer(Player player){
// TODO自动生成的方法存根
return新玩家();
}

@Override
@GET
@Path(/ getPlayer / {param})
public Player getPlayer(@PathParam(param )int id){
// TODO自动生成的方法存根
Player bla = new Player();
bla.setId(-1);
return bla;
}

@Override
@GET
public List< Player> getPlayers(){
// TODO自动生成的方法存根
返回null;
}

@Override
@GET
public List< Integer> getPlayerIDs(){
// TODO自动生成的方法存根
返回null;
}



}

和Player类。

  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;

私人字符串名称;

私人字符串密码;

阿凡达头像;

私人PlayerProperties属性;

private int tempId;

private int availablePropertyPoints;

private int totalPropertyPoints;

// @OneToMany
private ArrayList< AchievedAchievment>个成就;

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>();

回报成就;
}

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

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

if(aa1.getPlayer()!= this)
抛出新的RuntimeException(Player:Achievment已经提供给另一个用户);
else
achievments.add(aa1);


$ b $ / code $ / pre

有没有人知道为什么这样做没有工作?尝试已经评论几乎所有的东西,几个不同的Maven依赖关系,但它不会开始工作。



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



我希望你能帮助我,

kr,

解决方案

错误消息告诉你什么是错误的(你必须查找以开头的行):

b
$ b


严重:产生媒体类型冲突。资源方法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()可以产生相同的媒体类型。

SEVERE:产生媒体类型冲突。资源方法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()可以产生相同的媒体类型。

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

  @GET 
public List< Player> getPlayers()

@GET
public Player createUser()

@GET
public List< Integer> getPlayerIDs()



泽西岛无法确定在发送GET请求到机/播放机。您需要为其中一些端点定义单独的路径。



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


i've got a problem using jersey (1.8), maven and 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 SelectChannelConnector@0.0.0.0: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.

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

i hope you can help me,

kr,

解决方案

The error messages are telling you what is wrong (you have to look for lines starting with 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

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

@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.

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

这篇关于Jersey:com.sun.jersey.spi.inject.Errors $ ErrorMessagesException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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