o.s.web.servlet.PageNotFound没有GET的映射

时间:2018-11-14 09:03:58

标签: java spring spring-mvc spring-boot resttemplate

朋友,我正在使用spring数据中的RestController来消耗来自外部API的数据。

当我使用PostMan获取数据时,出现此404错误代码。 但是,如果我在POSTMAN上使用带有标头的直接URL,则会得到正确的数据和响应代码200

你能帮我吗

控制台Intelij

 
2018-11-13 17:30:42.334  WARN 11820 --- [nio-8080-exec-2] o.s.web.servlet.PageNotFound             : No mapping for GET /toto

这是我的控制器类


    package com.controller;

    import org.apache.log4j.Logger;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.http.*;
    import org.springframework.web.bind.annotation.CrossOrigin;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    import org.springframework.web.client.RestTemplate;

    import javax.json.Json;


    @RestController
    @CrossOrigin("*") // pour gere les erreu d'ente  ex: Orig
    public class FlightRestServives {
        private static Logger logger = Logger.getLogger(FlightRestServives.class.getName());


        @Autowired
        private RestTemplate restTemplate;

        String serviceURL = "https://api.klm.com/opendata/flightoffers/reference-data?country=NL";

        public FlightRestServives() {
        }

        //Consuming a service by GET method
        // @GetMapping("/test")
        @RequestMapping(
                value = "/toto",
                headers = {
                        "api-key=xmc3vburw886j9zqcsfrdu2t",
                        "AFKL-TRAVEL-Country=NL",
                        "AFKL-TRAVEL-Host=KL",
                        "X-Originating-IP=46.193.67.48"}
                /*produces = "application/json",
                consumes = "application/json",
                headers = {
                        "api-key=xmc3vburw886j9zqcsfrdu2t",
                        "AFKL-TRAVEL-Country=NL",
                        "AFKL-TRAVEL-Host=KL",
                        "X-Originating-IP=46.193.67.48"}*/
        )
        public Json getAvailableOperations() {

            logger.debug("Flight");
            HttpHeaders headers = new HttpHeaders();
            headers.add("api-key", "Keyyy");
            headers.add("AFKL-TRAVEL-Country", "NL");
            headers.add("AFKL-TRAVEL-Host", "KL");
            headers.add("X-Originating-IP", "46.193.67.48");

            HttpEntity requestEntity = new HttpEntity(headers);
            logger.debug("request entities  are: " + requestEntity);

            return restTemplate.getForObject(serviceURL, Json.class);
            /*return restTemplate
                    .exchange(
                            serviceURL,
                            HttpMethod.GET,
                            requestEntity,
                            Json.class
                    );*/
        }
    }

0 个答案:

没有答案