我正在尝试学习ReST的工作方式,并且试图做一个简单的测试项目来充当烟雾测试。我上了四节课。

@ApplicationPath("/rest")
public class RestApplication extends Application
{
}

...
@Path("/testClassURL")
@Stateless
public class TestClass {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/testMethodNoParamURL")
    public TestBean testMethod() {
        TestBean ret = new TestBean();
        ret.setNum(5);
        ret.setStr("9087".concat("1234"));
        return ret;
    }
}

另外两个是简单的类,仅包含getter和setter。您可以在那里看到它们。根据我设置的路径注释,我应该可以输入该网址
localhost:8080/TestWebRest/testClassURL/testMethodNoParamURL

这应该给我一个JSON响应。不幸的是,我得到的只是以下500错误
[2014-10-01T20:00:02.360-0400] [glassfish 4.0] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=24 _ThreadName=http-listener-1(4)] [timeMillis: 1412208002360] [levelValue: 900] [[
StandardWrapperValve[testyTest.RestApplication]: Allocate exception for servlet testyTest.RestApplication
java.lang.IllegalStateException: The resource configuration is not modifiable in this context.
at org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:257)
at org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:205)
at org.glassfish.jersey.server.ResourceConfig.register(ResourceConfig.java:435)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:261)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:167)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:349)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1225)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:237)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:745)

这看起来很熟悉吗?

最佳答案

原因是您对该URL调用有两个或多个适用的映射。

例如:

@Path("/{myParam}")

还有其他地方:
@Path("/{differentParam}")

07-27 15:00