Errors$ErrorMessagesException when using Jersey in Java

后端 未结 4 780
悲哀的现实
悲哀的现实 2021-01-18 17:05

I am using Jersy to develeop REST webservices, this is my simple code:

@GET
@Path(\"/retrieveCustomerInformation/{jsonString}\")
@Produces(MediaType.APPLICAT         


        
相关标签:
4条回答
  • 2021-01-18 17:34

    Your question seems to be a duplicate and has probably been appropriately addressed. I too had the same issue some time ago. Click here to see the accepted answer that resolved it for me

    And in case you're reluctant to follow the link, first of all, try adding jersey-multipart.jar and mimepull.jar to your project libraries... And if your project is a Maven project, add the following dependencies to your pom.xml. The mimepull dependency should ship along with it.

    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>1.8</version>
    </dependency>
    

    Remember to ensure that the version of jersey-multipart that you use, is the same as the version of jersey that you're using in the project.

    Just in case the above solution doesn't resolve your issue, you may want to see here for more useful tips too. Cheers!

    0 讨论(0)
  • 2021-01-18 17:44

    Add dependency from the reference

    Jersey Application Deployment and Runtime Environments

    in your web.xml

    <servlet>
        <servlet-name>jersey-serlvet</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.rest.portal</param-value>
        </init-param>
        <init-param>
            <param-name>jersey.config.server.provider.scanning.recursive</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>jersey.config.server.provider.classnames</param-name>
            <param-value>com.rest.portal.HelloWord</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
    

    In Jersey 1.x only using the

    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    

    In 2.x series use

    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    

    And add necessary jersy jar files

    1. asm-5.0.2.jar
    2. jersey-common.jar
    3. jersey-servlet-container-core.jar
    4. jersey-servlet-container.jar
    5. jersey-server.jar
    0 讨论(0)
  • 2021-01-18 17:59

    Check for clashing @Path annotations. This will result with the same error. It's a weird error for communicating path issues, but you can easily test it by renaming the matching paths.

    Example of cashing paths in the code below

    Some class

    @Path("/storage")
    public class BookingRestService {
    
    @GET
    @Path("/bookings")
    @Produces(value = MediaType.APPLICATION_XML)
    

    and another class

    @Path("/storage")
    public class StorageRestService {
    

    By renaming any of the @Path("/storage") the problem seizes to impair your work progress.

    0 讨论(0)
  • 2021-01-18 17:59

    One more use-case, which causes the same exception, which broke my code. If you were to write the resource like this:

    public String getPOST(@QueryParam("type") Character type){}
    

    the following data type, Character, will cause the exception.

    0 讨论(0)
提交回复
热议问题