Why would “java.lang.IllegalStateException: The resource configuration is not modifiable in this context.” appear deploying Jersey app?

前端 未结 15 860
孤街浪徒
孤街浪徒 2020-11-30 15:06

I have created an app implementing REST services locally using:

Eclipse Indigo Jersey 2.4 Tomcat 7.0.47

When running locally using Eclipse, the services work

相关标签:
15条回答
  • 2020-11-30 15:31

    I got the same error message. For me the problem was, that I used @RequestMapping (a Spring annotation) instead of the @QueryParam (JAX-RS annotation) on a method argument due to a copy paste. The error message was not that informative, but that was the problem for me.

    0 讨论(0)
  • 2020-11-30 15:34

    The issue in my case is that the shaded jar did not include the javassist package that Jersey uses to do bytecode manipulation. When shading a jar, make sure to include org.javassist:*.

        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.26.0-GA</version>
        </dependency>
    
    0 讨论(0)
  • 2020-11-30 15:36

    I solved this problem by adding this code into web.xml file

      <servlet>
        <servlet-name>jersey-serlvet</servlet-name>
        <servlet-class>
            com.sun.jersey.spi.container.servlet.ServletContainer
        </servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
      </servlet-mapping>
    
    0 讨论(0)
  • 2020-11-30 15:39

    In my case, I had a Jersey POST resource for file uploads. The resource specified the parameter: @FormDataParam("file") InputStream file

    and consumed MediaType.MULTIPART_FORM_DATA.

    To fix the issue, I had to add the following to the Jersey REST configuration in my web.xml file:

    <init-param>
        <param-name>jersey.config.server.provider.classnames</param-name>
        <param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
    </init-param>
    
    0 讨论(0)
  • 2020-11-30 15:40

    In my case it was just a missing @PathParam("id") for the 'int id' declaration. Wrong code:

    @POST
    @Path("{id}/messages")
    public Response returnMessages(int id, Message[] msgs) {
    

    Corrected code:

    @POST
    @Path("{id}/messages")
    public Response returnMessages(@PathParam("id") int id, Message[] msgs) {
    
    0 讨论(0)
  • 2020-11-30 15:40

    Add

    <build>
      <resources>
        <resource>
          <directory>src/main/resources</directory>
          <filtering>true</filtering>
        </resource>
      </resources>
    </build>
    
    0 讨论(0)
提交回复
热议问题