Spring mvc 当请求路径模板参数不是路径中的最后一个并部署到WebLogic 12.1.1时,如何使spring矩阵变量工作?
我一直在尝试使用一个矩阵变量来提供从概念上属于“/path/{param}/someotherpath”表单的请求路径参数的附加信息。 应用程序配置为支持矩阵变量(默认情况下为关闭)。 但是仍然没有成功,因此我根据spring MVC参考页面上提供的示例代码在spring pitclinic示例应用程序中创建了一个简化的测试用例:Spring mvc 当请求路径模板参数不是路径中的最后一个并部署到WebLogic 12.1.1时,如何使spring矩阵变量工作?,spring-mvc,weblogic12c,Spring Mvc,Weblogic12c,我一直在尝试使用一个矩阵变量来提供从概念上属于“/path/{param}/someotherpath”表单的请求路径参数的附加信息。 应用程序配置为支持矩阵变量(默认情况下为关闭)。 但是仍然没有成功,因此我根据spring MVC参考页面上提供的示例代码在spring pitclinic示例应用程序中创建了一个简化的测试用例: @Controller public class MatrixTestController { @RequestMapping(value = "/matri
@Controller
public class MatrixTestController
{
@RequestMapping(value = "/matrix/test/{petId}", method = RequestMethod.GET)
public String findPet(@PathVariable String petId,
@MatrixVariable(required=false, defaultValue="1") int q,
Model model) {
System.out.println("petId=" + petId + ", q=" + q);
model.addAttribute("petId", petId);
model.addAttribute("q", q);
return "matrixtest";
}
@RequestMapping(value = "/matrix/test/{petId}/paws", method = RequestMethod.GET)
public String findPet2(@PathVariable String petId,
@MatrixVariable(required=false, defaultValue="1") int q,
Model model) {
System.out.println("petId=" + petId + ", q=" + q);
model.addAttribute("petId", petId);
model.addAttribute("q", q);
return "matrixtest";
}
}
对于Tomcat,对这两个方法的请求均成功(q的值已从其默认值正确覆盖):
但是,对于WebLogic,只有对第一个方法的请求成功:
http://localhost:7001/spring-petclinic/matrix/test/1;q=3
对第二个的请求导致错误404--找不到页面:
http://localhost:7001/spring-petclinic/matrix/test/1;q=2/paws
第二个请求映射是我实际上希望在实际应用程序中使用的请求映射
到目前为止,我发现的唯一一个与问题相关的页面(但与Spring无关)是2011年的一个页面(与WebLogic的旧版本相关):
其中指出:
Tomcat是唯一理解路径的每个段都可以有参数的容器。其他所有参数都假定参数只能出现在最后一段上
在SpringMVC参考页()上,我没有找到任何关于部署到WebLogic时使用矩阵变量的信息。
我也没有在weblogic.xml部署描述符的描述中找到任何与URL中分号相关的内容
还有什么我可以忽略的吗?是否有可能需要为WebLogic另外启用的Spring配置参数
配置 mvc-core-config.xml(只是更改):
weblogic.xml(能够部署到weblogic):
符合事实的
符合事实的
/春季宠物诊所
antlr*
org.hibernate*
javax.persistence*
http://localhost:7001/spring-petclinic/matrix/test/1;q=2/paws
@Configuration
public class WebConfig extends DelegatingWebMvcConfiguration
{
@Bean
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping()
{
RequestMappingHandlerMapping handlerMapping = super.requestMappingHandlerMapping();
handlerMapping.setRemoveSemicolonContent(false);
handlerMapping.setUseTrailingSlashMatch(false);
return handlerMapping;
}
@Bean
@Override
public RequestMappingHandlerAdapter requestMappingHandlerAdapter()
{
RequestMappingHandlerAdapter handlerApapter = super.requestMappingHandlerAdapter();
handlerApapter.setIgnoreDefaultModelOnRedirect(true);
return handlerApapter;
}
}
<!-- <mvc:annotation-driven conversion-service="conversionService"/>-->
<mvc:annotation-driven conversion-service="conversionService" enable-matrix-variables="true" />
<!-- Used to change configuration for RequestMappingHandlerMapping removeSemicolonContent property which is needed for matrix variables support: -->
<bean class="WebConfig"/>
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
<jsp-descriptor>
<keepgenerated>true</keepgenerated>
<debug>true</debug>
</jsp-descriptor>
<context-root>/spring-petclinic</context-root>
<container-descriptor>
<prefer-application-packages>
<package-name>antlr.*</package-name>
<package-name>org.hibernate.*</package-name>
<package-name>javax.persistence.*</package-name>
</prefer-application-packages>
</container-descriptor>
<dispatch-policy>
</weblogic-web-app>