所以我花了很多时间来处理这个错误:
小概述;基本上做了一个简单的get调用来执行这种行为:
Mar 27, 2017 2:43:44 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 1 * Server responded with a response on thread 1530388690@qtp-1144748369-0
1 < 200
1 < Access-Control-Allow-Methods: GET POST, DELETE, PUT
1 < Access-Control-Allow-Origin: *
1 < Allow: OPTIONS
1 < Content-Type: application/json
Mar 27, 2017 2:43:45 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 2 * Server responded with a response on thread 1530388690@qtp-1144748369-0
2 < 500
正如您所看到的,它以正确的200响应但由于某种原因立即失败。经过几个小时的调试后,我意识到如果我没有映射多对多或一对多映射的集合,响应确实会失败。
以下是我正在进行所有映射的示例:
@ManyToMany
@JoinTable(name="user_specializations",
joinColumns=@JoinColumn(name="user_id"),
inverseJoinColumns=@JoinColumn(name="specialization_id")
)
private Collection<Specialization> specializationsList = new ArrayList<Specialization>();
@OneToMany(mappedBy = "user")
private Set<Research> researchSet = new HashSet<Research>();
当我映射这些时,响应失败,否则它不会那么也许它只是因为我的反应不是序列化但我甚至尝试过Gson和jackson注释但没有任何效果。 任何想法??
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{email}/getUser")
public Response getUserByEmail (@PathParam("email") String email){
ObjectMapper objectMapper = new ObjectMapper();
userInformation = new UserInformation();
UserDataPojo userData = userInformation.getPrimaryUserInfo(email);
return Response.ok()
.entity(userData)
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "GET POST, DELETE, PUT")
.allow("OPTIONS").build();
}