PolicyInquiryController

PolicyInquiryController

我正在尝试使用Spring MVC 3.0创建一些宁静的Web服务。我目前有一个问题,在任何给定时间我的2个控制器中只有1个可以工作。事实证明,按字母顺序排序的第一个类将正常工作。我得到的错误是:

handleNoSuchRequestHandlingMethod找不到与Servlet请求匹配的处理程序方法:路径'/polinq.xml',方法'GET',参数map [[empty]]

我之前也有一个非常相似的消息,除了不是地图为空,而是类似map [v-> String(array)]

不管出现什么消息,当前LocationCovgController都可以工作,而PolicyInquiryController不能。如果我将PolicyInquiryController的更改更改为APolicyInquiryController,则它将开始正确执行功能,并且LocationCovgController将停止工作。

任何帮助将不胜感激。

非常感谢你,
杰里米

下面提供的信息包括两个控制器类的框架以及定义如何设置spring的servlet配置文件。

控制器1

package org.example;
@Controller
@RequestMapping(value = "/polinq.*")
public class PolicyInquiryController {

    @RequestMapping(value = "/polinq.*?comClientId={comClientId}")
    public ModelAndView getAccountSummary(
        @PathVariable("comClientId") String commercialClientId) {
        // setup of variable as was removed.
        ModelAndView mav = new ModelAndView("XmlView",
            BindingResult.MODEL_KEY_PREFIX + "accsumm", as);
        return mav;
    }
}


控制器2

package org.example;

@Controller
@RequestMapping(value = "/loccovginquiry.*")
public class LocationCovgController {
    @RequestMapping(value = "/loccovginquiry.*method={method}")
    public ModelAndView locationCovgInquiryByPolicyNo(
        @PathVariable("method")String method) {
        ModelAndView mav = new ModelAndView("XmlView",
            BindingResult.MODEL_KEY_PREFIX + "loccovg", covgs);
        return mav;
    }
}


Servlet配置

<context:component-scan base-package="org.example." />

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"     p:order="0">
  <property name="mediaTypes">
    <map>
      <entry key="atom" value="application/atom+xml"/>
      <entry key="xml" value="application/xml"/>
      <entry key="json" value="application/json"/>
      <entry key="html" value="text/html"/>
    </map>
   </property>

  <property name="defaultContentType" value="text/html"/>
  <property name="ignoreAcceptHeader" value="true"/>
  <property name="favorPathExtension" value="true"/>
  <property name="viewResolvers">
     <list>
         <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/jsp/"/>
            <property name="suffix" value=".jsp"/>
          </bean>
      </list>
   </property>
   <property name="defaultViews">
      <list>
        <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"/>
      </list>
  </property>
</bean>

<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />

<bean id="XmlView" class="org.springframework.web.servlet.view.xml.MarshallingView">
  <property name="marshaller" ref="marshaller"/>
</bean>

<oxm:jaxb2-marshaller id="marshaller">
  <oxm:class-to-be-bound name="org.example.policy.dto.AccountSummary"/>
  <oxm:class-to-be-bound name="org.example.policy.dto.InsuredName"/>
  <oxm:class-to-be-bound name="org.example.policy.dto.Producer"/>
  <oxm:class-to-be-bound name="org.example.policy.dto.PropertyLocCoverage"/>
  <oxm:class-to-be-bound name="org.example.policy.dto.PropertyLocCoverages"/>
</oxm:jaxb2-marshaller>

最佳答案

您应该使用@RequestParam而不是@PathVariable来绑定请求参数(即,在?之后的参数,也不需要将它们包含在@RequestMapping中)。另外,您无需在类级别使用@RequestMapping进行此配置:

控制器1

package org.example;

@Controller
public class PolicyInquiryController {
    @RequestMapping(value = "/polinq")
    public ModelAndView getAccountSummary(
        @RequestParam("comClientId") String commercialClientId) {
        // setup of variable as was removed.
        ModelAndView mav = new ModelAndView("XmlView",
            BindingResult.MODEL_KEY_PREFIX + "accsumm", as);
        return mav;
    }
}


控制器2

package org.example;

@Controller
public class LocationCovgController {
    @RequestMapping(value = "/loccovginquiry")
    public ModelAndView locationCovgInquiryByPolicyNo(
        @RequestParam("method") String method) {
        ModelAndView mav = new ModelAndView("XmlView",
            BindingResult.MODEL_KEY_PREFIX + "loccovg", covgs);
        return mav;
    }
}

08-27 10:29