在JavaREST服务中获取json

在JavaREST服务中获取json,java,json,rest,jakarta-ee,glassfish,Java,Json,Rest,Jakarta Ee,Glassfish,我从本地主机上通过netbeans提供了一个restful服务,并选择glassfish 4.1.1作为我的Web服务器 然后我想测试一下。 当它想给我一个xml响应时,它工作了,但当我试图得到一个JSON响应时,它给了我一个500错误,如下所示 GET RequestFailed RequestFailed --> Status: (500) Response: { HTTP Status 500 - Internal Server Error type Exception re

我从本地主机上通过netbeans提供了一个restful服务,并选择glassfish 4.1.1作为我的Web服务器 然后我想测试一下。 当它想给我一个xml响应时,它工作了,但当我试图得到一个JSON响应时,它给了我一个500错误,如下所示

GET RequestFailed RequestFailed --> Status: (500) 
Response: {

HTTP Status 500 - Internal Server Error


type Exception report

messageInternal Server Error

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

exception 
javax.servlet.ServletException: javax.ejb.EJBException


root cause 
javax.ejb.EJBException


root cause 
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Error Code: 0


root cause 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Error Code: 0


root cause 
java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.


root cause 
javax.resource.spi.ResourceAllocationException: Error in allocating a connection. Cause: Connection could not be allocated because: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.


root cause 
com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.


root cause 
com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.


root cause 
com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.


root cause 
javax.resource.spi.ResourceAllocationException: Connection could not be allocated because: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.


root cause 
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.


root cause 
java.net.ConnectException: Connection refused: connect


note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1.1 logs.


GlassFish Server Open Source Edition 4.1.1 

}
我在web和stack上搜索,发现它是因为eclipselink而出现的,所以我用eclipselink 2.6.3和2.6.1对它进行了测试,并重新安装了我的localhost,但再次出现错误:

GET RequestFailed RequestFailed --> Status: (500) 
Response: {
HTTP Status 500 - Internal Server Error

type Exception report

messageInternal Server Error

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

exception

javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper
root cause

org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper
root cause

java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1.1 logs.

GlassFish Server Open Source Edition 4.1.1


}
对不起,我的英语不好
非常感谢您花时间解决我的问题,即使只是阅读它。

stacktrace显示java.lang.NoClassDefFoundError代码失败

java.lang.NoClassDefFoundError:无法初始化类 org.eclipse.persistence.jaxb.BeanValidationHelper

确保运行时期间存在org.eclipse.persistence.jaxb.BeanValidationHelper类依赖关系

您可以阅读更多关于NoClassDefFoundError@

=========================================================================== 更新:


玻璃鱼4.1.1中似乎有一只虫子。JIRA仍然开放。泽西岛上也有一个吉拉。最后,他们为这个问题提供了一些解决方法。请仔细使用该解决方案。

为了使解决方案更加醒目和清晰


记录到上面的答案,在这种情况下,您不需要使用glassfish 4.1.1,只需安装glassfish 4.1,问题就解决了(因为解决4.1.1错误花费了我太长的时间,我建议您不要尝试解决它

在netbeanse restful项目中,我没有web.pom。我应该如何找到它的工作方式?GlassFish 4.1.1似乎有一个bug。JIRA仍然开放。我已经更新了我的答案。希望您能够让它与中提到的解决方法一起工作。是的,它是4.1.1中大约1年前的错误。我将glassfish更改为4.1,所有功能正常。谢谢您的时间。您可以从服务器发布相关代码吗?