我正在使用Spring Boot 1.5.7,Spring Data REST,Spring HATEOAS,Hibernate,Spring Validation,Swagger .

我通过Spring Data REST公开了所有的存储库 . 它工作得很好,但是当我暴露一个嵌套的对象列表时我遇到了问题 .

我们来看看这个例子:

@Entity
public class TicketBundle extends AbstractEntity {

    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY,mappedBy="ticketBundle")
    @OnDelete(action = OnDeleteAction.NO_ACTION)
    private List<MovementTicketBundle> payments = new ArrayList<>();

这是我的运动超级

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type")
public class Movement extends AbstractEntity {
    @Column(nullable = false)
    protected String description;

这是 TicketBundle 使用的特定类:

@Entity
@DiscriminatorValue(value = "ticketBundle")
public class MovementTicketBundle extends Movement {
    private static final long serialVersionUID = 3949580014012377816L;

    @ManyToOne(fetch = FetchType.LAZY)
    TicketBundle ticketBundle;

我为每个bean都有一个存储库:

@Transactional
@PreAuthorize("isAuthenticated()")
public interface MovementRepository extends PagingAndSortingRepository<Movement, Long> {
}

和@Transactional @PreAuthorize(“isAuthenticated()”)公共接口MovementTicketBundleRepository扩展PagingAndSortingRepository {}

@Transactional
@PreAuthorize("isAuthenticated()")
public interface TicketBundleRepository extends PagingAndSortingRepository<TicketBundle, Long> {
}

在Swagger中我看到了 TicketBundle

enter image description here

我正在尝试使用应该返回 MovementTicketBundle 列表的 endpoints GET http://localhost:8080/api/v1/ticketBundles/1/payments . 相反,这是发生的事情:

curl -X GET --header 'Accept: application/hal+json' 'http://localhost:8080/api/v1/ticketBundles/1/payments'

response code :405 response body :无内容 response headers

{
  "allow": "POST",
  "content-length": "0",
  "date": "Fri, 13 Oct 2017 07:52:11 GMT",
  "x-application-context": "application:prod",
  "x-content-type-options": "nosniff",
  "x-frame-options": "DENY",
  "x-xss-protection": "1; mode=block",
  "content-type": null
}

如果嵌套的资源是一个bean,一切都有效 . 问题出在我列出的时候 . 我错过了什么吗?你有什么建议来解决这个问题吗?我没有看到关于这个问题的其他问题 .