【发布时间】:2023-03-30 14:30:01
【问题描述】:
我有一个 Java REST-Service,它提供了一个向客户端返回 JSON 的服务(使用 Tomcat 和 Jersey)。我一直在寻找这个问题好几天了,但我真的不明白,因为服务器提供了另一个几乎相同的调用,并且工作正常...... REST 服务:
//working
@GET
@Path("/listAll")
@Produces({ MediaType.APPLICATION_JSON })
public List<Route> getAllRoutes() {
EntityManager em = getEntityManager();
Query q = em.createQuery("select r from Route r ");
@SuppressWarnings("unchecked")
List<Route> routeList = q.getResultList();
em.close();
return routeList;
}
MySQL 表 'waypoint' 包含 3 列:ID(BIGINT)、COORDINATE(VARCHAR)、ROUTEID(BIGINT)。如果这很重要,该项目将在 Liferay 上运行....就像我说的那样,我再也没有 f***** 的想法了:/ 奇怪的是“/listAll”调用工作正常,但“/getPoints”返回500 并且日志只显示:
connection: 2015-01-13 18:10:47.715--ServerSession(27137311)--Thread(Thread[http-bio-8080-exec- 21,5,main])--client acquired: 18571860
[EL Finer]: transaction: 2015-01-13 18:10:47.715--ClientSession(18571860)--Thread(Thread[http-bio-8080-exec-21,5,main])--acquire unit of work: 32602042
[EL Finer]: transaction: 2015-01-13 18:10:47.715--UnitOfWork(32602042)--Thread(Thread[http-bio-8080-exec-21,5,main])--begin unit of work flush
[EL Finer]: transaction: 2015-01-13 18:10:47.715--UnitOfWork(32602042)--Thread(Thread[http-bio-8080-exec-21,5,main])--end unit of work flush
[EL Finest]: query: 2015-01-13 18:10:47.715--UnitOfWork(32602042)--Thread(Thread[http-bio-8080-exec-21,5,main])--Execute query ReadAllQuery(referenceClass=WayPoint sql="SELECT ID, ROUTEID, COORDINATE FROM WAYPOINT")
[EL Finest]: connection: 2015-01-13 18:10:47.715--ServerSession(27137311)--Connection(21934325)--Thread(Thread[http-bio-8080-exec-21,5,main])--Connection acquired from connection pool [default].
[EL Finest]: connection: 2015-01-13 18:10:47.715--ServerSession(27137311)--Connection(21934325)--Thread(Thread[http-bio-8080-exec-21,5,main])--Connection released to connection pool [default].
[EL Finer]: transaction: 2015-01-13 18:10:47.715--UnitOfWork(32602042)--Thread(Thread[http-bio-8080-exec-21,5,main])--begin unit of work commit
[EL Finer]: transaction: 2015-01-13 18:10:47.715--UnitOfWork(32602042)--Thread(Thread[http-bio-8080-exec-21,5,main])--end unit of work commit
[EL Finer]: transaction: 2015-01-13 18:10:47.715--UnitOfWork(32602042)--Thread(Thread[http-bio-8080-exec-21,5,main])--release unit of work
谢谢你们;)
问候
【问题讨论】:
-
你试过调试吗?它调用方法吗?尝试调试 getPoints 方法,看起来它正在抛出异常并且它被隐藏为 500 错误响应。通过调试,您可以发现,或者至少尝试从方法内部打印一些内容,以了解发生了哪些异常,只是为了进行测试。
-
上一个日志中的“ReadAllQuery”是否与对“/getPoints”端点的调用相关联?请务必先排除 SQL 错误,即您的查询 + 映射的行为符合您的预期。
-
我怎样才能得到这个 sql 错误? @Inanda Menezes 我不知道为什么,显然我太笨了,但我的 Eclipse 在调试过程中找不到 REST 服务器源...可能是因为我通过批处理文件而不是 Eclipse IDE 部署更改?
标签: java mysql json jersey internal-server-error