在Spring中遇到了post方法的问题。当我尝试将对象发布到数据库时,客户端应用程序已挂起,我需要终止它。带卷曲的物体正常工作。我正在获取日志:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: java.util.ArrayList[0]->dareq.Point["points"]->java.util.ArrayList[0]->dareq.Point["points"]->java.util.ArrayList[0]->dareq.Point["points"]->java.util.ArrayList[0]->dareq.Point["points"]
客户端:
积分班:
public class Point {
private Long id;
private List<String> bssid = new ArrayList<>();
private List<Double> rssi = new ArrayList<>();
private double x;
private double y;
public Point()
{
}
public Point(Long id, List<String> bssid, List<Double> rssi, double x, double y){
this.id = id;
this.bssid = bssid;
this.rssi = rssi;
this.x = x;
this.y = y;
}
发布功能:
public void postPoint()
{
RestTemplate restTemplate = new RestTemplate();
restTemplate.postForObject("http://localhost:5000/points", this, this.getClass());
}
服务器端:
控制器:
@PostMapping("/points")
Points newPoints(@RequestBody Points newPoints){
return repository.save(newPoints);
}
积分等级:
@Data
@Entity
public class Points {
private @Id @GeneratedValue Long id;
@Column
@ElementCollection
private List<String> bssid;
@Column
@ElementCollection
private List<Double> rssi;
private double x;
private double y;
Points (){
};
Points(List<String> bssid, List<Double> rssi, double x, double y){
this.bssid=bssid;
this.rssi=rssi;
this.x=x;
this.y=y;
}
}
在AWS服务器上检查日志,当我尝试在客户端上发布对象时,会调用很多get方法:
78.28.26.200 - - [07/Jan/2019:00:34:31 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:32 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:32 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:32 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:32 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:32 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:33 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:33 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:33 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:33 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:33 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:33 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:33 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:34 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:34 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:34 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:34 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:34 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:34 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:34 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:35 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:35 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:35 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:35 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:35 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
78.28.26.200 - - [07/Jan/2019:00:34:36 +0000] "GET /points/ HTTP/1.1" 200 87 "-" "Java/1.8.0_172" "-"
我将非常感谢您的帮助。谢谢