SPRING 4에서 @ResponseBody 사용시 아래 오류가 발생할 경우 해결 :

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

 

pom.xml 에서 아래 내용 삭제

<dependency>
   
<groupId>org.codehaus.jackson</groupId>
   
<artifactId>jackson-core-asl</artifactId>
   
<version>1.9.13</version>
</dependency>
<dependency>
   
<groupId>org.codehaus.jackson</groupId>
   
<artifactId>jackson-mapper-asl</artifactId>
   
<version>1.9.13</version>
</dependency>

 

아래 내용 추가

<dependency>
   
<groupId>com.fasterxml.jackson.jaxrs</groupId>
   
<artifactId>jackson-jaxrs-base</artifactId>
   
<version>2.4.4</version>
</dependency>

 

dispatcher-servlet.xml 내용 수정

<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="mediaTypes" >
           <value>
                json=application/json
                xml=application/xml
           </value>
      </property>
 </bean>

+ Recent posts