Spring Data REST 返回 http 405 请求嵌套资源列表

2024-01-28

我正在使用 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> {
}

和 @事务性 @PreAuthorize("isAuthenticated()") 公共接口 MovementTicketBundleRepository 扩展 PagingAndSortingRepository { }

and

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

在 Swagger 中我看到了我的TicketBundle:

我正在尝试使用端点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,则一切正常。问题是当我列出清单时。我错过了什么吗?您有一些解决问题的建议吗?我没有看到关于这个问题的其他问题。


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring Data REST 返回 http 405 请求嵌套资源列表 的相关文章

随机推荐