Spring Data REST返回http 405,询问嵌套资源列表

时间:2017-10-13 07:56:04

标签: spring spring-mvc spring-data-rest spring-hateoas

我正在使用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()”)     public interface MovementTicketBundleRepository扩展了PagingAndSortingRepository {     }

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

在Swagger中,我看到了TicketBundle

enter image description here

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

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

响应代码:405 响应正文:没有内容 响应标题

{
  "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,一切正常。问题出在我列出的时候。我错过了什么吗?你有什么建议来解决这个问题吗?我没有看到关于这个问题的其他问题。

0 个答案:

没有答案