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
在客户端服务中使用外部客户端时,Spring数据Rest Hateoas资源对象为空_Spring_Spring Mvc_Spring Boot_Spring Data Rest_Spring Hateoas - Fatal编程技术网

在客户端服务中使用外部客户端时,Spring数据Rest Hateoas资源对象为空

在客户端服务中使用外部客户端时,Spring数据Rest Hateoas资源对象为空,spring,spring-mvc,spring-boot,spring-data-rest,spring-hateoas,Spring,Spring Mvc,Spring Boot,Spring Data Rest,Spring Hateoas,我最近尝试使用Spring Boot 1.4.1和Spring cloud Camden SR1从这个和这个复制Spring cloud示例,但遇到了一个问题。当客户端服务使用外部客户端调用生产者服务时,反序列化的资源没有内容或链接 进一步挖掘之后,问题似乎与映射Jackson2HttpMessageConverter有关,它是JacksonObjectMapper。当我查看外国客户的SpringDecoder使用的HttpMessageConverters时,我看到了2个MappingJack

我最近尝试使用Spring Boot 1.4.1和Spring cloud Camden SR1从这个和这个复制Spring cloud示例,但遇到了一个问题。当客户端服务使用外部客户端调用生产者服务时,反序列化的资源没有内容或链接

进一步挖掘之后,问题似乎与映射Jackson2HttpMessageConverter有关,它是JacksonObjectMapper。当我查看外国客户的SpringDecoder使用的HttpMessageConverters时,我看到了2个MappingJackson2HttpMessageConverters,但是转换器的对象映射器都没有注册Jackson2HalModule

Spring数据Rest预订服务应用程序类:

@EnableDiscoveryClient
@SpringBootApplication
public class ReservationServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(ReservationServiceApplication.class, args);
    }
}
@Entity
public class Reservation extends BaseEntity {
    private String reservationName;

    public Reservation(String reservationName) {
        this.reservationName = reservationName;
    }

    protected Reservation() {}

    public String getReservationName() {
        return reservationName;
    }
}
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class ReservationClientApplication {
    public static void main(String[] args) {
        SpringApplication.run(ReservationClientApplication.class, args);
    }
}
预订类别:

@EnableDiscoveryClient
@SpringBootApplication
public class ReservationServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(ReservationServiceApplication.class, args);
    }
}
@Entity
public class Reservation extends BaseEntity {
    private String reservationName;

    public Reservation(String reservationName) {
        this.reservationName = reservationName;
    }

    protected Reservation() {}

    public String getReservationName() {
        return reservationName;
    }
}
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class ReservationClientApplication {
    public static void main(String[] args) {
        SpringApplication.run(ReservationClientApplication.class, args);
    }
}
BaseEntity类具有ID和版本

ReservationRepository类:

@RepositoryRestResource
public interface ReservationRepository extends CrudRepository<Reservation, Integer> {
}
预订客户端外部客户端类:

@FeignClient("reservation-service")
public interface ReservationServiceClient {
    @RequestMapping(method = RequestMethod.GET, value = "reservations")
    Resources<Reservation> getReservations();
}
到保留客户端应用程序类。这导致客户端对保留资源进行反序列化并正确返回。不幸的是,我还尝试了一些其他类,它们具有Java 8LocalDateTime字段,需要在ObjectMapper上注册Java 8 Jackson模块,但当我查看正在使用的ObjectMapper时,唯一注册的模块是Jackson2HalModule


如果我做得不正确或者存在bug,我将非常感谢您的建议。谢谢

经过进一步挖掘,我终于解决了这个问题。客户端应用程序需要spring数据rest依赖项来正确设置消息转换器。不幸的是,考虑到客户端应用程序不需要spring数据存储库,这似乎有点违反直觉。

看看。作为一个解决办法,你可以配置一个自定义解码器,为我做了这个技巧。谢谢你的回答,经过几天的搜索,它最终帮助了我。附加信息:依赖项缺失错误也是springs openfeign的一个问题,而不仅仅是netflix.feign
@EnableHypermediaSupport(type=EnableHypermediaSupport.HypermediaType.HAL)