草庐IT

banner_data

全部标签

spring - 如何配置 Spring Data REST 以返回为 POST 请求创建的资源的表示?

我正在关注spring-data-rest指南AccessingJPADatawithREST.当我http发布一条新记录时,它会被插入(响应是201)。太好了,但是有没有办法配置RESTMVC代码以返回新创建的对象?我宁愿不必发送搜索请求来查找新实例。 最佳答案 您不必搜索创建的实体。正如HTTP规范所建议的那样,返回状态代码201Created的POST请求应该包含一个Locationheader,其中包含资源的URI刚刚创建。因此,您需要做的就是有效地向该特定URI发出GET请求。SpringDataREST在Reposito

java - 使用 Spring Data Rest 时公开所有 ID

我想使用SpringRest接口(interface)公开所有ID。我知道默认情况下,这样的ID不会通过rest接口(interface)公开:@Id@GeneratedValue(strategy=GenerationType.IDENTITY)@Column(unique=true,nullable=false)privateLongid;我知道我可以使用它来公开User的ID:@ConfigurationpublicclassRepositoryConfigextendsRepositoryRestMvcConfiguration{@Overrideprotectedvoidco

spring - 对 Spring-Data DDD 存储库模式感到困惑

我不太了解DDD存储库模式,但Spring中的实现让我感到困惑。publicinterfacePersonRepositoryextendsJpaRepository{…}由于接口(interface)扩展了JpaRepository(或MongoDBRepository...),如果您从一个db更改为另一个,您也必须更改接口(interface)。对我来说,接口(interface)是用来提供一些抽象的,但在这里它不是那么抽象......你知道为什么Spring-Data会这样工作吗? 最佳答案 你是对的,从外部的角度来看,接口(

spring - 如何避免使用 Spring Data Rest 进行 n+1 查询?

问题。如何避免使用SpringDataREST进行n+1次查询?背景。在查询SpringDataREST以获取资源列表时,每个生成的顶级资源都具有指向关联资源的链接,而不是将关联资源直接嵌入到顶部级资源。例如,如果我查询数据中心列表,相关区域会显示为链接,如下所示:{"links":[{"rel":"self","href":"http://localhost:2112/api/datacenters/1"},{"rel":"datacenters.DataCenter.region","href":"http://localhost:2112/api/datacenters/1/re

java - 为什么 Spring Data 存储库上的 getOne(...) 不会抛出 EntityNotFoundException?

我正在处理一个奇怪的问题,我正在做集成测试,调用我的Controller从数据库中获取一个不存在的对象。publicOptionalget(Longid){try{returnOptional.ofNullable(repository.getOne(id));}catch(EntityNotFoundExceptione){returnOptional.empty();}}当getOne(…)找不到任何东西时,我期待EntityNotFoundException但实际上什么也没有。如果我检查我的结果,我可以看到我有一个带有指向它的处理程序链接的空实体“抛出EntityNotFound

spring - 在 STS 3.1 的 Spring Data JpaRepository 接口(interface)中到处出现 "Invalid derived query"错误

我们已经完全按照SpringData文档中的说明实现了我们的存储库。在我们从STS2.9升级到STS3.1之前,一切都很好。所有试图让这些错误消失的尝试都失败了,在某些情况下甚至没有意义!它们与界面或使用的实体中的任何属性都不匹配!这是一个例子:publicinterfaceCreditNotesRepositoryextendsJpaRepository{CreditNotesfindCurrentCreditNotes(LongshipmentDetailId);}findCurrentCreditNotes是我们实体中的命名查询。这段代码执行得很好。@NamedQueries({

java - IntelliJ IDEA 无法解析 spring data jpa @query 注释中的实体

这是我的repository界面:publicinterfaceContentRepositoryextendsJpaRepository{@Query(value="selectcfromContentcwherec.ContentCategory.genre=:genreandc.ContentType.genre=:contentType")IterablefindByTypeAndCategory(@Param("contentType")StringcontentType,@Param("genre")Stringgenre);}这是内容POJO:@Entity@Table(

java - spring-data-jpa 和 spring-boot-starter-data-jpa 的区别

这可能不是最好的问题,但我注意到有2个SpringJPA用于Springboot。它们有何不同?目前,我正在尝试与Hibernate一起设置SpringBoot1.5.3项目。我记得我之前用spring-boot-starter-data-jpa用JPA设置了SpringBoot。我看到的大多数在线示例以及starter.spring.io都为SpringJPA提供了以下依赖项。org.springframework.bootspring-boot-starter-data-jpa但在一个现有项目中,我遇到了spring-data-jpa:org.springframework.dat

spring - 如何在 Spring Boot 中选择性地升级依赖项? (样例: Spring Data)

我使用SpringBoot(1.4.1)的SpringDataJPAstarter。它包含SpringDataJPA1.10.3。但是,我需要使用此版本spring数据中尚不存在的@DomainEvents注释。当我尝试添加最新版本的SpringDataJPA时,我的应用程序运行时出现错误。我的pom示例:org.springframework.bootspring-boot-starter-parent1.4.1.RELEASE...org.springframework.bootspring-boot-starter-data-jpa...当我尝试像这样添加最新版本的SpringD

java - 无法在 xd-singlenode 上使用 spring-data-jpa 部署 spring-xd 处理器模块

我有一个spring-xd处理器模块,它依赖于使用spring-data-jpa的项目:xd-processor模块的pom.xml:org.test.commonorg.test.common0.0.1-SNAPSHOTorg.test.common的pom.xml:org.springframework.bootspring-boot-starter-data-jpa如果我运行integrationtest一切正常。但是部署到xd-singlenode(1.2.0.RELEASE)失败并出现以下错误:2015-06-21T20:50:35+02001.2.0.RELEASEERRO