我正在尝试将我的项目更新到 Spring Boot 2.0.5 版本。这是一个简单的github 项目
重要组成部分:
@Entity
@Table(name = "placement")
public class Placement {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(updatable = false)
private Long id;
private String name;
@ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.REMOVE)
private PlacementType type;
//... getters and setters
}
@Entity
@Table(name = "placement_type")
public class PlacementType {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(updatable = false)
private Long id;
private String name;
//... getters and setters
}
@RepositoryRestResource(collectionResourceRel = "placement", path = "placement")
public interface PlacementRepository extends
PagingAndSortingRepository<Placement, Long> {}
@RepositoryRestResource(collectionResourceRel = "placementType", path = "placementType")
public interface PlacementTypeRepository extends
PagingAndSortingRepository<PlacementType, Long> {}
构建.gradle
buildscript {
ext {
springBootVersion = '2.0.5.RELEASE'
}
...
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-data-rest:${springBootVersion}")
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.3.6.Final'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate5', version: '2.9.0'
compile 'com.h2database:h2:1.4.196'
}
问题:
当我启动应用程序时,两个 api 端点都可以正常工作:
GET http://localhost:8090/api/placement/ => 200 works fine
GET http://localhost:8090/api/placementType => 200 works fine
但是在我从 Placement uri ( @ManyToOne)访问 PlacementType 之后,我无法再访问 PlacementType 端点:
GET http://localhost:8090/api/placement/1/type => 200 works fine
GET http://localhost:8090/api/placementType => 404 (and default spring error screen)
没有错误日志,或者我的日志级别可能不正确,但我不知道为什么第二次将请求重定向到 SimpleUrlHandlerMapping。
慕森卡
相关分类