1. 程式人生 > >Could not find acceptable representation

Could not find acceptable representation

json https param tor default dia iteye logs tps

報了一個這個異常:

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

通過這篇文章找到了“favorPathExtension”關鍵字,
Spring Boot完美解決(406)Could not find acceptable representation原因及解決方法
進而找到了這篇文章中的方法,解決了問題
SpringMVC restful風格

    <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" />
    
    <bean id="contentNegotiationManager"
          class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
        <property name="favorPathExtension" value="false" />
        <property name="favorParameter" value="true" />
        <property name="parameterName" value="mediaType" />
        <property name="ignoreAcceptHeader" value="true"/>
        <property name="useJaf" value="false"/>
        <property name="defaultContentType" value="application/json" />

        <!--<property name="mediaTypes">
            <map>
                <entry key="json" value="application/json" />
                <entry key="xml" value="application/xml" />
            </map>
        </property>-->
    </bean>

Could not find acceptable representation