几乎相同的Spring Rest请求返回不同的响应,如何理解Spring跟踪?

时间:2015-03-06 16:49:40

标签: rest spring

我有两个几乎相同的控制器连接到两个不同的JPA Spring数据存储库。 JPA请求正常运行,已经过测试。

我在同一台服务器上有其他请求可以正常运行。为什么两个几乎相同的不同请求没有响应正确的响应?

如何从Spring跟踪中找到有关此问题的提示?我收到Status not found请求:

type Status report

message /hospital/EditWard/HOSP1/

description The requested resource is not available.

在控制台中我看到了这个痕迹:

2015-03-06 11:45:16,686 DEBUG [org.springframework.web.servlet.DispatcherServlet] - DispatcherServlet with name 'dispatcher' processing GET request for [/hospital/EditWard/HOSP1/]
2015-03-06 11:45:16,686 DEBUG [org.springframework.web.servlet.DispatcherServlet] - DispatcherServlet with name 'dispatcher' processing GET request for [/hospital/EditWard/HOSP1/]
2015-03-06 11:45:16,687 DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - Looking up handler method for path /EditWard/HOSP1/
2015-03-06 11:45:16,687 DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - Looking up handler method for path /EditWard/HOSP1/
2015-03-06 11:45:16,689 DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - Did not find handler method for [/EditWard/HOSP1/]
2015-03-06 11:45:16,689 DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - Did not find handler method for [/EditWard/HOSP1/]
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - Matching patterns for request [/EditWard/HOSP1/] are [/**]
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - Matching patterns for request [/EditWard/HOSP1/] are [/**]
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - URI Template variables for request [/EditWard/HOSP1/] are {}
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - URI Template variables for request [/EditWard/HOSP1/] are {}
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - Mapping [/EditWard/HOSP1/] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@23c3853d] and 1 interceptor
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - Mapping [/EditWard/HOSP1/] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@23c3853d] and 1 interceptor
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Last-Modified value for [/hospital/EditWard/HOSP1/] is: -1
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Last-Modified value for [/hospital/EditWard/HOSP1/] is: -1
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Successfully completed request
2015-03-06 11:45:16,690 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Successfully completed request

这是我的控制者:

package com.freschelegacy.controller;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import com.freschelegacy.model.Ward;

import com.freschelegacy.model.WardId;
import com.freschelegacy.service.WardService;
import com.freschelegacy.service.data.EditWardDTO;
import com.freschelegacy.service.ServiceException;

import com.freschelegacy.repository.WardRepository;

@RestController()
public class EditWardController {

    @Autowired
    private WardRepository wardRepository;

    @Autowired
    private WardService wardService;

    private final Logger logger = LoggerFactory.getLogger(EditWardController.class);


    @Transactional(readOnly=true)
    @RequestMapping(value = "/EditWard", method=RequestMethod.GET, produces = "application/json;charset=utf-8")
    public Page<EditWardDTO> getEditWard(@PathVariable String hospitalCode, @RequestParam(value= "page", required = false, defaultValue = "0" ) int page, 
                                         @RequestParam(value = "size", required = false, defaultValue = "10"  ) int size){

        Pageable pageable = new PageRequest(page, size);   
        Page<EditWardDTO> pageEditWard = wardRepository.editWard(hospitalCode, pageable);
        return pageEditWard;
    }
}

1 个答案:

答案 0 :(得分:0)

我已将此 / {hospitalCode)添加到@Request映射的值中。现在它有效。

@RequestMapping(value ="/EditWard/{hospitalCode}", method=RequestMethod.GET, produces = "application/json;charset=utf-8")