Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring数据REST端点消失(休眠冲突)_Java_Spring_Spring Mvc_Spring Boot_Spring Data Rest - Fatal编程技术网

Java Spring数据REST端点消失(休眠冲突)

Java Spring数据REST端点消失(休眠冲突),java,spring,spring-mvc,spring-boot,spring-data-rest,Java,Spring,Spring Mvc,Spring Boot,Spring Data Rest,我正在尝试将我的项目更新到SpringBoot2.0.5版本。这是 简单的 基本部分: @Entity @Table(name = "placement") public class Placement { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(updatable = false) private Long id; private String name;

我正在尝试将我的项目更新到SpringBoot2.0.5版本。这是 简单的

基本部分:

@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> {}
问题:

启动应用程序时,两个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)
没有错误日志,或者我的日志级别不正确,但我不知道为什么请求会被重定向到SimpleRhlHandlerMapping第二次

 LOG from first GET http://localhost:8090/api/placementType => 200 
 02:38:56.076 [http-ni] DEBUG o.s.w.s.DispatcherServlet                - DispatcherServlet with name 'dispatcherServlet' processing GET request for [/api/placementType] 
 02:38:56.080 [http-ni] DEBUG s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /api/placementType 
 02:38:56.088 [http-ni] DEBUG s.w.s.m.m.a.RequestMappingHandlerMapping - Did not find handler method for [/api/placementType] 
 02:38:56.114 [http-ni] DEBUG o.s.w.s.DispatcherServlet                - Last-Modified value for [/api/placementType] is: -1 
 Hibernate: select placementt0_.id as id1_1_, placementt0_.name as name2_1_ from placement_type placementt0_ limit ?
 02:38:56.559 [http-ni] DEBUG m.m.a.RequestResponseBodyMethodProcessor - Written [PagedResource { content: [Resource { content: com.varren.model.PlacementType@65e962bd, links: [<http://localhost:8090/api/placementType/1>;rel="self", <http://localhost:8090/api/placementType/1>;rel="placementType"] }], metadata: Metadata { number: 0, total pages: 1, total elements: 1, size: 20 }, links: [<http://localhost:8090/api/placementType{?page,size,sort}>;rel="self", <http://localhost:8090/api/profile/placementType>;rel="profile"] }] as "application/hal+json" using [org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration$ResourceSupportHttpMessageConverter@446c8c72] 
 02:38:56.562 [http-ni] DEBUG o.s.w.s.DispatcherServlet                - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling 
 02:38:56.563 [http-ni] DEBUG o.s.w.s.DispatcherServlet                - Successfully completed request 

                 GET http://localhost:8090/api/placement/1/type => 200 works fine
 LOG from second GET http://localhost:8090/api/placementType => 404 
 03:09:08.285 [http-ni] DEBUG o.s.w.s.DispatcherServlet                - DispatcherServlet with name 'dispatcherServlet' processing GET request for [/api/placementType] 
 03:09:08.286 [http-ni] DEBUG s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /api/placementType 
 03:09:08.287 [http-ni] DEBUG s.w.s.m.m.a.RequestMappingHandlerMapping - Did not find handler method for [/api/placementType] 
 03:09:08.292 [http-ni] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping        - Matching patterns for request [/api/placementType] are [/**] 
 03:09:08.292 [http-ni] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping        - URI Template variables for request [/api/placementType] are {} 
 03:09:08.292 [http-ni] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping        - Mapping [/api/placementType] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/], ServletContext resource [/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@74eec640]]] and 1 interceptor 
 03:09:08.293 [http-ni] DEBUG o.s.w.s.DispatcherServlet                - Last-Modified value for [/api/placementType] is: -1 
 03:09:08.294 [http-ni] DEBUG o.s.w.s.DispatcherServlet                - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling 
 03:09:08.294 [http-ni] DEBUG o.s.w.s.DispatcherServlet                - Successfully completed request 
从第一次获取日志http://localhost:8090/api/placementType => 200 
02:38:56.076[http ni]调试o.s.w.s.DispatcherServlet-名为“DispatcherServlet”的DispatcherServlet正在处理[/api/placementType]的GET请求
02:38:56.080[http ni]调试s.w.s.m.m.a.RequestMappingHandlerMapping-查找路径/api/placementType的处理程序方法
02:38:56.088[http ni]调试s.w.s.m.a.RequestMappingHandlerMapping-未找到[/api/placementType]的处理程序方法
02:38:56.114[http ni]调试o.s.w.s.DispatcherServlet-[/api/placementType]的上次修改值为:-1
休眠:从placement类型placementt0\uLimit中选择placementt0\uId作为id1\u1\uId,placementt0\uName作为name2\u1\uId?
02:38:56.559[http ni]调试m.m.a.RequestResponseBodyMethodProcessor-编写[PagedResource{content:[Resource{content:com.varren.model。PlacementType@65e962bd,链接:[;rel=“self”,;rel=“placementType”]}],元数据:元数据{number:0,总页数:1,总元素数:1,大小:20},链接:[;rel=“self”,;rel=“profile”]}]as使用[org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration]的“application/hal+json”$ResourceSupportHttpMessageConverter@446c8c72] 
02:38:56.562[http ni]调试o.s.w.s.DispatcherServlet-返回给名为“DispatcherServlet”的DispatcherServlet的Null ModelAndView:假设HandlerAdapter完成了请求处理
02:38:56.563[http ni]调试o.s.w.s.DispatcherServlet-已成功完成请求
得到http://localhost:8090/api/placement/1/type =>200工作正常
从第二个开始记录http://localhost:8090/api/placementType => 404 
03:09:08.285[http ni]调试o.s.w.s.DispatcherServlet-名为“DispatcherServlet”的DispatcherServlet正在处理[/api/placementType]的GET请求
03:09:08.286[http ni]调试s.w.s.m.m.a.RequestMappingHandlerMapping-查找路径/api/placementType的处理程序方法
03:09:08.287[http ni]调试s.w.s.m.a.RequestMappingHandlerMapping-未找到[/api/placementType]的处理程序方法
03:09:08.292[http ni]调试o.s.w.s.h.SimpleUrlHandlerMapping-请求[/api/placementType]的匹配模式为[/**]
03:09:08.292[http ni]调试o.s.w.s.h.SimpleUrlHandlerMapping-请求[/api/placementType]的URI模板变量为{}
03:09:08.292[http ni]调试o.s.w.s.h.SimpleUrlHandlerMapping-使用handler[ResourceHttpRequestHandler[locations=[class path resource[META-INF/resources/],class path resource[resources/],class path resource[static/],class path resource[public/],ServletContext resource[/]将[/api/placementType]映射到HandlerExecutionChain,resolvers=[org.springframework.web.servlet.resource。PathResourceResolver@74eec640]]]和1个拦截器
03:09:08.293[http ni]调试o.s.w.s.DispatcherServlet-[/api/placementType]的上次修改值为:-1
03:09:08.294[http ni]调试o.s.w.s.DispatcherServlet-返回给名为“DispatcherServlet”的DispatcherServlet的Null ModelAndView:假设HandlerAdapter已完成请求处理
03:09:08.294[http ni]调试o.s.w.s.DispatcherServlet-已成功完成请求

还有一件事。大多数时候我都有这个bug,但有时一切都正常。我在github repo中添加了第二个@Entity,以表明有时两个相同的实体中的一个可以工作,另一个不能工作,但可能我遗漏了一些明显的问题,看起来问题出在不推荐的
hibernate entitymanager中,或者至少是一个版本不匹配

compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.3.6.Final'
我花了几天时间才意识到不再需要它,我应该切换到
hibernate core
。但是切换到最新的hibernate core也产生了同样的问题,所以我必须完全删除依赖项,让
spring boot starter数据jpa
使用它的版本(
5.2.17.最终版
用于启动
2.0.5.发行版

RepositoryRestHandlerMapping.lookupHandlerMethod
中使用断点对此进行了调试,并在RepositoryRestHandlerMapping缓存中注意到奇怪的
class com.varren.model.PlacementType$HibernateProxy


正常(工作)版本如下所示(没有HibernateProxy):

非常奇怪。我现在唯一要尝试的是将属性名称从
PlacementType;
更改为
PlacementType PlacementType;
@Patrick是的,尝试了几次。还测试了几个java版本。切换到boot 2.0.6。经过几天的调试,我觉得使用最新版本太愚蠢了属于休眠entitymanager
,并且从不尝试删除依赖项。
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.3.6.Final'