问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
通过fegin请求的controller
package com.example.controller;
import com.example.pojo.Ticket;
import com.example.service.TicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/consumer")
public class UserFeginController {
@Autowired
private TicketService ticketService = null;
@GetMapping("/selectAll")
public List<Ticket> selectAll(){
return ticketService.selectAll();
}
@PostMapping("/insertTicket")
public boolean insertTicket(){
return ticketService.insertTicket();
}
@GetMapping("/getTicket/{id}")
public Ticket getTicket(@PathVariable Long id){
return ticketService.getTicket(id);
}
}
请求的接口
package com.example.service;
import com.example.pojo.Ticket;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import java.util.List;
@Service
@FeignClient(value = "PROVIDER-TICKET")
public interface TicketService {
@GetMapping("/ticket/selectAll")
public List<Ticket> selectAll();
@PostMapping("/ticket/insertTicket")
public boolean insertTicket();
@GetMapping("/ticket/getTicket/{id}")
public Ticket getTicket(@PathVariable("id") Long id);
}
运行结果及报错内容
控制台输出
2022-01-10 22:11:31.407 WARN 20484 --- [io-8081-exec-10] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused by handler execution: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: No serializer found for class com.example.pojo.Ticket and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class com.example.pojo.Ticket and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.ArrayList[0])
浏览器报错
我的解答思路和尝试过的方法
百度说添加getset方法,但是有@Data注解了