今天写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的坑,也不知道啥原因.希望大神多多指教…