gpt4 book ai didi

java - 学习 REST,卡在 IllegalStateException

转载 作者:搜寻专家 更新时间:2023-11-01 01:42:44 24 4
gpt4 key购买 nike

我正在尝试为工作学习 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 组成的简单类。你可以在那里看到它们。根据我设置的路径注释,我应该可以输入这个 URL

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}")

关于java - 学习 REST,卡在 IllegalStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26152578/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com