java.lang.IllegalArgumentException: No converter found for return value of type

后端 未结 20 2067
夕颜
夕颜 2020-11-30 00:04

With this code

@RequestMapping(value = \"/bar/foo\", method = RequestMethod.GET)
    public ResponseEntity foo() {

        Foo model;
        ...         


        
20条回答
  •  渐次进展
    2020-11-30 00:48

    I had the very same problem, and unfortunately it could not be solved by adding getter methods, or adding jackson dependencies.

    I then looked at Official Spring Guide, and followed their example as given here - https://spring.io/guides/gs/actuator-service/ - where the example also shows the conversion of returned object to JSON format.

    I then again made my own project, with the difference that this time I also added the dependencies and build plugins that's present in the pom.xml file of the Official Spring Guide example I mentioned above.

    The modified dependencies and build part of XML file looks like this!

    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    
    
    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    
    

    You can see the same in the mentioned link above.

    And magically, atleast for me, it works. So, if you have already exhausted your other options, you might want to try this out, as was the case with me.

    Just a side note, it didn't work for me when I added the dependencies in my previous project and did Maven install and update project stuff. So, I had to again make my project from scratch. I didn't bother much about it as mine is an example project, but you might want to look for that too!

提交回复
热议问题