2016-08-20 40 views
0

這是我的春天-web.xml中控制器用SpringMVC不能返回appliation/JSON只是返回HTTP 406

<?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:mvc="http://www.springframework.org/schema/mvc" 
      xmlns:context="http://www.springframework.org/schema/context" 
      xsi:schemaLocation="http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans.xsd 
      http://www.springframework.org/schema/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context.xsd"> 

     <mvc:annotation-driven/> 

     <mvc:default-servlet-handler/> 

     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
      <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
      <property name="prefix" value="/WEB-INF/jsp/"/> 
      <property name="suffix" value=".jsp"/> 
     </bean> 


     <context:component-scan base-package="org.twtpush.web"/> 
    </beans> 

這是pom.xml的

<dependency> 
     <groupId>com.fasterxml.jackson.core</groupId> 
     <artifactId>jackson-core</artifactId> 
     <version>2.5.4</version> 
    </dependency> 

    <dependency> 
     <groupId>com.fasterxml.jackson.core</groupId> 
     <artifactId>jackson-databind</artifactId> 
     <version>2.5.4</version> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations --> 
    <dependency> 
     <groupId>com.fasterxml.jackson.core</groupId> 
     <artifactId>jackson-annotations</artifactId> 
     <version>2.5.4</version> 
    </dependency> 

,這是我的控制器

@Controller 
@RequestMapping("/push") 
public class PushController { 

    private final Logger logger = LoggerFactory.getLogger(this.getClass()); 

    @Autowired 
    private IPushService pushService; 

    @RequestMapping(value = "/{a}/push", 
      method = RequestMethod.GET, 
      produces = {"application/json;charset=UTF-8"}) 
    @ResponseBody 
    public Operate pu(@PathVariable("a") String a){ 
     Operate operate = new Operate(true,a,0001); 
     return operate; 
    } 
} 

我在我的網絡瀏覽器中訪問過「http://localhost:8080/push/test/push」。

但......

***** HTTP狀態406 - 類型狀態報告消息 描述 由該請求所標識的資源僅能夠與根據不可接受的特徵產生響應的請求「接受」標題。 Apache Tomcat/8.0.36 *****

非常感謝!

回答