Spring RequestMapping不适用于控制器类方法

时间:2014-06-15 11:40:02

标签: java spring-mvc

Tomcat日志:

Jun 15, 2014 4:55:50 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI[/test_mvc/service/countryservice/countrybycode/US] in DispatcherServlet with name 'DispatcherServlet'

调度程序servlet的WEB.xml usrl映射:

<servlet-mapping>
   <servlet-name>DispatcherServlet</servlet-name>
   <url-pattern>*.action</url-pattern>
   <url-pattern>/service/*</url-pattern>
</servlet-mapping>

Controller Method是以下控制器类中的getCountryByCode:

 @Controller
 public class CountryController {
 @Autowired
CountryDAOImpl countryService;

@RequestMapping(value="/service/countryservice/countrybycode/{code}" , method=RequestMethod.GET)
@ResponseBody
public String getCountryByCode(@PathVariable("code") String code){
    String country = null;
    if(code != null){
        try {
            country = countryService.getCountryByCode(code)  ;
        } catch (DAOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return country;         
}

@RequestMapping(value="/service/countryservice/countriesbycodes/{codes}" , method=RequestMethod.GET)
@ResponseBody
public List<String> getCountryListByCodeList(@RequestParam("codes") List codeList){
    List<String> countryList = null;
    countryList = countryService.getCountriesByCodes(codeList);
    return countryList;     
}   

@Controller public class CountryController { @Autowired CountryDAOImpl countryService; @RequestMapping(value="/service/countryservice/countrybycode/{code}" , method=RequestMethod.GET) @ResponseBody public String getCountryByCode(@PathVariable("code") String code){ String country = null; if(code != null){ try { country = countryService.getCountryByCode(code) ; } catch (DAOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return country; } @RequestMapping(value="/service/countryservice/countriesbycodes/{codes}" , method=RequestMethod.GET) @ResponseBody public List<String> getCountryListByCodeList(@RequestParam("codes") List codeList){ List<String> countryList = null; countryList = countryService.getCountriesByCodes(codeList); return countryList; } 一切成功执行没有在控制台日志上观察到任何错误,只要我点击网址:http:// :9999 / test_mvc / service / countryservice / countrybycode / US(这是一个在此处发布的虚拟URL有一个不同的IP地址),我得到404错误,日志有上面提到的警告。我怀疑有一些相关的网址映射,我错过了这里

0 个答案:

没有答案