(HttpMessageNotWritableException ) No converter found for return value of type xxxx

最近在家沒事兒,寫寫代碼玩,用了Maven構建SSM項目,結果提示以下信息spring

org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class com.lcy.pojo.User
【緣由】找不到返回值類型的轉換器,找了很久發現controller返回的是json格式數據

【方案】在maven的pox.xml中只引入Json的依賴時,只引入了「jackson-core」;沒有引入 「jackson-databind」,添加了依賴後問題解決了。
【提示】當controller標記@ResponseBody後,會用解析器去解析Controller的返回值,解析器會去尋找SpringMvc中註冊的HttpMeesageConverter接口的實現類,結果由於沒有添加對應的依賴,因此
就找不到Json類型的轉換器了,添加依賴後就正常了。



【正確的依賴】
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
        <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.9.8</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.9.8</version>
        </dependency>
相關文章
相關標籤/搜索