为什么是"java.lang.IllegalStateException:在此上下文中无法修改资源配置".出现正在部署的Jersey应用程序? [英] Why would "java.lang.IllegalStateException: The resource configuration is not modifiable in this context." appear deploying Jersey app?

查看:559
本文介绍了为什么是"java.lang.IllegalStateException:在此上下文中无法修改资源配置".出现正在部署的Jersey应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用以下方法在本地实施REST服务的应用程序:

I have created an app implementing REST services locally using:

Eclipse靛蓝 泽西岛2.4 Tomcat 7.0.47

Eclipse Indigo Jersey 2.4 Tomcat 7.0.47

使用Eclipse在本地运行时,服务可以正常运行,但是在部署WAR文件时,尝试对服务URL之一进行GET时会遇到以下异常:

When running locally using Eclipse, the services work OK, but when deploying my WAR file, I get the following exception when trying to do a GET to one of the services URL:

HTTP Status 500 - Servlet.init() for servlet com.app.rest.MyResourceConfig threw exception

type Exception report

message Servlet.init() for servlet com.app.rest.MyResourceConfig threw exception

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet com.app.rest.MyResourceConfig threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    java.lang.Thread.run(Thread.java:662)

root cause

java.lang.IllegalStateException: The resource configuration is not modifiable in this context.
    org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:270)
    org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:218)
    org.glassfish.jersey.server.ResourceConfig.register(ResourceConfig.java:448)
    org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:300)
    org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:167)
    org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:349)
    javax.servlet.GenericServlet.init(GenericServlet.java:160)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    java.lang.Thread.run(Thread.java:662)

我一直找不到根本原因,我唯一的怀疑是它可能是缺少的运行依赖项或Eclipse中与我自己的本地Tomcat服务器环境以及远程服务器上的Tomcat不同的其他配置.

I've been unable to find yet a root cause and my only suspicion is that it might be a missing running dependency or some other configuration in Eclipse that differ from my own local Tomcat server environment and the Tomcat at remote server.

我在资源配置类中的代码是:

My code at the resource configuration class is:

package com.app.rest;

import javax.ws.rs.ApplicationPath;
import org.glassfish.jersey.server.ResourceConfig;

import com.app.rest.services.RunDetailsService;
import com.app.rest.services.RunHistoryService;
import com.app.rest.services.RunPollService;
import com.app.rest.services.RunTestService;


@ApplicationPath("api")
public class MyResourceConfig extends ResourceConfig {

    public MyResourceConfig() {
        register(RunHistoryService.class).
        register(RunTestService.class).
        register(RunDetailsService.class).
        register(RunPollService.class);     
    }   
}

您认为可能是什么原因?

What do you think would be a possible cause?

推荐答案

一个可能的原因是您对该URL调用有两个或多个适用的映射.

One possible cause is that you have two or more applicable mappings for that URL call.

例如:

@Path("/{myParam}")

@Path("/{myParam}")

还有其他地方:

@Path("/{differentParam}")

@Path("/{differentParam}")

现在,泽西岛无法告知实际上应该调用哪种方法并给出此错误.

Now Jersey have no way of telling what method is actually supposed to be called and gives this error.

这篇关于为什么是"java.lang.IllegalStateException:在此上下文中无法修改资源配置".出现正在部署的Jersey应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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