SpringCloud 整合JPA Feign远程调用报415 Unsupported Media Type

	今天写cloud整合jpa feign来负载均衡.但是从消费者通过feign来用生产者接口时,突然报了一个415
	
		ERROR 41780 --- [nio-6001-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is feign.FeignException: status 415 reading ConsultFeign#updateStatus(Consult); content:
{"timestamp":1574683530783,"status":415,"error":"Unsupported Media Type","exception":"org.springframework.web.HttpMediaTypeNotSupportedException","message":"Content type 'application/json;charset=UTF-8' not supported","path":"/consult/updateStatus"}] with root cause

以上是错误信息,检查时一直以为是POST传参错误,

消费者

@PostMapping("/updateStatus")
public boolean updateStatus(@RequestBody Consult consult){
    System.err.println(consult);
    return consultFeign.updateStatus(consult);
}

feign接口

@PostMapping("/consult/updateStatus")
boolean updateStatus(@RequestBody Consult consult);

接口提供者

@PostMapping("/updateStatus")
public boolean updateStatus(@RequestBody Consult consult){
    return consultService.updateStatus(consult);
}

因为之前调用传递对象也没出问题 所有就在实体类找



import com.fasterxml.jackson.annotation.JsonBackReference;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;


@Entity(name = "docter")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Docter implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer doctorId;

    private String name;

    private Integer renzheng;

    private Integer goods;

    private String img;

    @OneToMany
    @Fetch(FetchMode.JOIN)
    @JoinColumn(name = "doctorId")
    @JsonBackReference
    private Set<Consult> consults = new HashSet<>();

}

突然发现Data注解中有toString方法 在操作多方是可能会出错,抱着试试看的态度删掉@Data
手写getset
之后就可以调用了.

@Entity(name = "mzy_docter")
public class Docter implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer doctorId;

    private String name;

    private Integer renzheng;

    private Integer goods;

    private String img;

    @OneToMany
    @Fetch(FetchMode.JOIN)
    @JoinColumn(name = "doctorId")
    private Set<Consult> consults = new HashSet<>();


    public Integer getDoctorId() {
        return doctorId;
    }

    public void setDoctorId(Integer doctorId) {
        this.doctorId = doctorId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getRenzheng() {
        return renzheng;
    }

    public void setRenzheng(Integer renzheng) {
        this.renzheng = renzheng;
    }

    public Integer getGoods() {
        return goods;
    }

    public void setGoods(Integer goods) {
        this.goods = goods;
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }

    public Set<Consult> getConsults() {
        return consults;
    }
    @JsonBackReference
    public void setConsults(Set<Consult> consults) {
        this.consults = consults;
    }
}

可能是jpa的坑,也不知道啥原因.希望大神多多指教…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值