2014-06-09 2 views
0

Ok, RESTful JSON을 제공하는 Spring 3.2 프로젝트에서 작업하고 있습니다.Spring 3.2 애플리케이션이 JSON 서비스를 제공하지 않아 406 오류가 발생했습니다.

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
version="2.5"> 
<servlet> 
    <servlet-name>saltCityWifi</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/config/servlet-config.xml</param-value> 
    </init-param> 
</servlet> 
<servlet-mapping> 
    <servlet-name>saltCityWifi</servlet-name> 
    <url-pattern>/*</url-pattern> 
</servlet-mapping> 
<display-name>Salt City Wifi</display-name> 
</web-app> 

이 서블릿-config.xml 파일 :

나는이 web.xml을 가지고

package com.saltcitywifi.controller; 

import java.util.List; 

import org.springframework.stereotype.Controller; 
import org.springframework.ui.Model; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.ResponseBody; 

import com.saltcitywifi.model.HotSpot; 
import com.saltcitywifi.service.HotSpotService; 
import com.saltcitywifi.service.HotSpotServiceImpl; 

@Controller 
public class HotSpotController { 
@RequestMapping(value="/hotSpot", method = RequestMethod.GET) 
public @ResponseBody List<HotSpot> getHotSpots() { 
    HotSpotService hotSpotService = new HotSpotServiceImpl(); 
    List<HotSpot> spots = hotSpotService.getAllHotSpots();  
    return spots; 
} 
} 

모든 것이 잘 작업했다 : 여기

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:p="http://www.springframework.org/schema/p" 
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> 
<context:component-scan base-package="com.saltcitywifi" /> 
<mvc:annotation-driven /> 
</beans> 

나의 컨트롤러 금요일에이 프로젝트에 대해 조금 배우려고 갑자기 406 오류가 발생했습니다. "thi가 식별 한 자원 요청은 "요청" "헤더"에 따라 수용 할 수없는 특성을 가진 응답 만 생성 할 수 있습니다. "

필자는 어떤 이유로 Jackson Jackson 종속성이 더 이상 내 빌드 경로에 포함되어 있지 않다고 생각합니다. 그러나 빌드 경로 구성을 클릭하면 Maven 종속성 폴더 내부에 jar 파일이 표시됩니다.

위와 관련한 도움을 주시면 대단히 감사하겠습니다. 프로젝트 정리/업데이트를 시도하고이 비슷한 문제를 골라서 읽으십시오.

답변

0

UGH. 질문을 게시 한 후에 마침내 알아 냈습니다. localhost : 8080/myapp/my-route.html로 이동했습니다.

localhost : 8080/myapp/my-route.json 또는 localhost : 8080/myapp/my-route로 이동하면 예상대로 올바르게 작동합니다.

406 오류는 내 응용 프로그램에서 문제가되지 않았습니다. 요청에 문제가있었습니다. 사용 가능한 HTML 응답이 없지만 web.xml 파일에서 .html 요청을 수락합니다. 내가 url 패턴을 선언 할 때/*.

바라건대 누군가는 이것을보고 잠재적 종속성을 추적하고 경로 문제를 구축하는 데 걸리는 시간을 피하고 올바른 요청을하는 법을 배워야합니다.