1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable...

Discussão em 'Angular' iniciado por Bhushan Mahajan, Outubro 2, 2024.

  1. I am developing chat application using java springboot and Angular 7. I am using events in spring boot and angular. I am trying to generate events in spring boot for angular to listen the event. However, I am getting following error:

    Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]


    Here is my controller code in springboot:

    @CrossOrigin("*")
    @RestController
    @RequestMapping("/chat")
    public class MessageController {

    @Autowired
    MessageService messageService;

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    private static final Logger logger = LoggerFactory.getLogger(MessageController.class);

    @PostMapping(consumes = "application/json", produces = "application/json")
    public GenericApiResponse<Map<String, Object>>message(@RequestBody MessageRequest req) {
    logger.info("MessageController:: messagemethod [POST] /chat");
    GenericApiResponse<Map<String, Object>> responseObj = new GenericApiResponse<>();
    Object returnValue = new Object();
    try {
    returnValue = messageService.translateText(req);
    } catch (Exception e) {
    e.printStackTrace();
    logger.error("EXCEPTION: "+e.getStackTrace().toString());
    responseObj.setStatus(Constants.ERROR);
    responseObj.setMessage("Internal Server Error");
    }
    Map<String, Object> resMap = new HashMap<>();
    resMap.put("result", returnValue);
    resMap.put("sender", req.getSender());
    responseObj.setResponseObject(resMap);
    responseObj.setStatus(Constants.SUCCESS);

    MessageEvent messageEvent = new MessageEvent(this,"eventName", responseObj);
    applicationEventPublisher.publishEvent(messageEvent);

    return responseObj;
    }


    I am unable to figure out what is the issue and how to solve it. Please help me to solve this issue. Thanks in advance :)

    Continue reading...

Compartilhe esta Página