0
votes

this is my spring-web.xml

<?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>

this is 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>

and this is my controller

@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;
    }
}

I visited "http://localhost:8080/push/test/push" in my web Browser.

but ...

*****HTTP Status 406 - type Status report message description The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers. Apache Tomcat/8.0.36*****

1

1 Answers

0
votes

Use Postman and send a HTTP GET request to http://localhost:8080/push/test/push with the request's Accept header set to the appropriate value in your case application/json.