我正在尝试使用Spring MVC 3.0创建一些宁静的Web服务。我目前有一个问题,即我的2个控制器中只有一个在任何给定时间都可以工作。事实证明,按字母顺序排序时,哪个类首先出现都能正常工作。我得到的错误是:
handleNoSuchRequestHandlingMethod没有为servlet请求找到匹配的处理程序方法:path'/polinq.xml',方法'GET',参数map [[empty]]
我之前也有一个非常类似的消息,除了地图是空的,它就像map [v - > String(array)]
无论消息如何,目前LocationCovgController都有效,而PolicyInquiryController则没有。如果我将PolicyInquiryController的更改更改为APolicyInquiryController,那么它将正确启动函数并且LocationCovgController将停止工作。
非常感谢任何协助。
非常感谢, 杰里米
下面提供的信息包括两个控制器类的框架以及定义如何设置spring的servlet配置文件。
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;
}
}
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;
}
}
<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>
答案 0 :(得分:1)
我看到的问题是类级别的注释,为您的情况尝试删除它们,只需在方法级别使用注释。此外,如果您再次收到错误,请发布堆栈跟踪。
还使用RequestParam来获取param值,使用PathVariable来访问pathvariables。只需使用网址\home\user\{username}\?p=rand
,即可获取username
使用路径变量并使用requestparam获取p
答案 1 :(得分:1)
您应该使用@RequestParam
代替@PathVariable
来绑定请求参数(即?
之后的参数,您也不需要将它们包含在@RequestMapping
中) 。此外,此类配置在类级别不需要@RequestMapping
:
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;
}
}
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;
}
}
答案 2 :(得分:0)
我停止并启动了websphere,代码开始工作。以前我只是简单地“发布”了对webpshere的更改或“清理”了RAD(Rational Application Developer)中的项目,看起来这些选项都没有完全刷新服务器上的代码。现在,代码可以100%的时间工作。