资源配置在此上下文实体中不可修改Resfutl Service [英] The resource configuration is not modifiable in this context entities Resfutl Service

查看:207
本文介绍了资源配置在此上下文实体中不可修改Resfutl Service的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Java还是很陌生,正在尝试我的第一个JPA项目,同时尝试将我的头放在Netbeans创建的所有对象上.我使用向导从数据库表中创建了一个用户" JPA实体.然后,我去了存在超类的AbstractFacade.java,添加了一个新方法,该方法将通过用户的电子邮件地址查找特定用户.

I'm fairly new to Java and working on my first JPA project while trying to wrap my head around all of the objects that Netbeans created. I created a "User" JPA entity from a database table using the wizard. Then I went to the AbstractFacade.java where the super class exists to add a new method that will find a specific user by their email address.

public T findFromEmail(String mailbox) {
    javax.persistence.Query q = getEntityManager().createNamedQuery("Users.findByEmail").setParameter("email", mailbox);
    return (T)q.getSingleResult();
}

接下来,我转到UsersFacaceRest.java并添加了以下方法.我不确定在这个示例中为什么需要@override,因为我似乎没有覆盖任何底层对象,但是如果我不覆盖,则Netbeans会给我一个错误.

Next I went to UsersFacaceRest.java and added the following method. I'm not sure why I needed the @override in this example as I didn't seem to be overriding any underlying object, but Netbeans gave me an error if I didn't.

@GET
@Path("{mailbox}")
@Produces({"application/xml", "application/json"})
@Override
public Users findFromEmail(@PathParam("mailbox") String mailbox) {
    return super.findFromEmail(mailbox);
}

现在,我收到以下错误消息:

Now I receive the following error:

    WebModule[/LMSWebService]StandardWrapper.Throwable 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:246) 
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:724)

我还需要做些其他事情来将方法添加到静态服务中吗,或者我的语法不正确吗?任何帮助将不胜感激.

Is there something else I need to do to add a method to the restful service or is my syntax incorrect? Any help would be greatly appreciated.

谢谢.

推荐答案

好吧,您似乎正在使用JAX-RS声明RESTful Web服务(或 Jersey (参考实现).

Well, you seem to be declaring a RESTful web service using JAX-RS (or Jersey, the reference implementation).

作为我提出了另一个问题,当出现初始化错误时,通常会引发此异常.您正在使用某种生成器(NetBeans向导)的事实表明,还有其他一些代码会被初始化.

As I've posted on another question this exception usually is thrown when there is an initialization error. The fact that you are using some kind of generator (NetBeans wizard) suggest there is some other code thrown arount to do the initialization.

JAX-RS是一个出色的RESTful规范,Jersey是参考实现.它写得很好,并且有据可查.因此,我建议去阅读文档,尤其是初始化部分 ,因此您可以将问题追根溯源.

JAX-RS is an excellent RESTful specification and Jersey is the reference implementation. It's well written and well documented. So I suggest to go and read the documentation, especially the initialization part, so you can trace your problem to its root.

这篇关于资源配置在此上下文实体中不可修改Resfutl Service的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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