No message body writer found : JSON : Apache CXF : RestFul Webservices

前端 未结 6 1885
春和景丽
春和景丽 2021-01-13 06:20

I am using Apache CXF for making a simple restful application. I have a client class which posts a JSON object to the server and server returns back a JSON after some manipu

6条回答
  •  被撕碎了的回忆
    2021-01-13 07:19

    I also had this problem, any of above solutions didn't work for me. Inorder to resolve this issue you need to do a couple of things which I will explain.

    In cxf-servlet.xml(server configuration) one of json providers needs to be provided.

             
                
                    
                
                 
                    
                
                 
                     
                 
               
              
    

    In the client, it can be configured using spring or source code itself. Here is the how it is done in source code itself.

     WebClient client = WebClient.create("http://localhost:9763/services/api/", Collections.singletonList(new JacksonJsonProvider()))
                    .path("categoryservice/category/001").accept(MediaType.APPLICATION_JSON_TYPE);
     Category category = client.get(Category.class);
    

    So here I have a class called Category, that is why I have done in that way. So now I hope you could understand how to resolve this error. One more thing needs to tell about URLs. When you create a WebClient instance need to give where is the service is deployed.And add a relative path to the desired endpoint using path as shown above example code.

提交回复
热议问题