Jersey: com.sun.jersey.spi.inject.Errors$ErrorMessagesException
hibernate, java, maven, rest, web-services
Solution
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.
Problem
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,