我将PostgreSQL与PostGIS一起使用来存储MultiPolygon地理空间数据
CREATE TABLE voivodeships
(
id INTEGER NOT NULL CONSTRAINT geotable_new_pk PRIMARY KEY,
name VARCHAR,
geometry GEOMETRY(MultiPolygon, 4326);
我在Spring Boot中创建了实体,存储库和控制器,如下所示:
实体:
@Entity
@Table(name = "voivodeships")
public class Voivodeship {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotBlank
private String name;
@Column
private MultiPolygon geometry;
// getters and setters omitted
}
存储库:
public interface VoivodeshipRepository extends JpaRepository<Voivodeship, Long> { }
控制器:
@RestController
public class VoivodeshipController {
@Autowired
VoivodeshipRepository voivodeshipRepository;
@GetMapping("/voiv/{id}")
public Voivodeship getVoivodeshipById(@PathVariable(value = "id") Long id) {
return voivodeshipRepository.findById(id).orElseThrow(()->new ResourceNotFoundException("Voivodeship " + id + " not found"));
}
}
但是在localhost:8080/voiv/1
上我得到了:
nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle
完全例外:
<html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Tue Oct 23 14:26:44 CEST 2018</div><div>There was an unexpected error (type=Internal Server Error, status=500).</div><div>Type definition error: [simple type, class org.geolatte.geom.crs.AngularUnit]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle (through reference chain: com.kswr.spring.boot.postgis.demo.postgisdemo.model.Voivodeship["geometry"]->org.geolatte.geom.MultiPolygon["coordinateReferenceSystem"]->org.geolatte.geom.crs.Geographic2DCoordinateReferenceSystem["coordinateSystem"]->org.geolatte.geom.crs.EllipsoidalCoordinateSystem2D["axes"]->org.geolatte.geom.crs.GeodeticLongitudeCSAxis[0]->org.geolatte.geom.crs.GeodeticLongitudeCSAxis["unit"]->org.geolatte.geom.crs.AngularUnit["fundamentalUnit"]->org.geolatte.geom.crs.AngularUnit["fundamentalUnit"])</div></body></html>