Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc @占位符不起作用的RequestMapping_Spring Mvc - Fatal编程技术网

Spring mvc @占位符不起作用的RequestMapping

Spring mvc @占位符不起作用的RequestMapping,spring-mvc,Spring Mvc,因此,我花了几个小时的时间试图让这篇文章的答案生效: 但它确实不起作用。到目前为止,我所拥有的: springmvc-servlet.xml <context:property-placeholder location="classpath:numbernick.properties"/> <context:component-scan base-package="com.numbernick" /> <context:annotation-config />

因此,我花了几个小时的时间试图让这篇文章的答案生效:

但它确实不起作用。到目前为止,我所拥有的:

springmvc-servlet.xml

<context:property-placeholder location="classpath:numbernick.properties"/>
<context:component-scan base-package="com.numbernick" />
<context:annotation-config />
numbernick.properties:

requestmapping.test=myUrl
这应该行得通。当我调用该页面时,会收到一条日志消息,上面写着“Test:myUrl” . 但是当我调用“/${requestmapping.test},html”时会出现这种情况。它应该可以调用“/myUrl.html”。我完全不知道为什么会这样。显然,PropertyPlaceholder可以工作,但不能同时工作。(顺便说一句:它是一个嵌套的RequestMapping。但是它在ToplVLRequestMapping中也不起作用)


这是怎么回事?我能做些什么来解决这个问题?我目前正在使用spring verion 3.2.8

我也遇到了这个问题,当我意识到一个
PropertyPlaceHolderConfigure
bean没有加载到存在许多占位符的模块上下文中时,我就解决了这个问题

简单的解决方案是重构我们的外部化配置。最后,我将
@PropertySources
定义和
propertyplaceholderconfigure
bean移动到一个公共模块,一切正常:

@Configuration
@PropertySources(value = {@PropertySource("classpath:app-config.properties")})
public class ExternalizedConfig {

@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
    return new PropertySourcesPlaceholderConfigurer();
}
像这样的请求映射现在可以正常工作了:

@RequestMapping(value="/${foo.bar.rest_proxy_uri}/**", method = RequestMethod.GET)
事实上,在服务器启动时,您将看到占位符已被解析:

2015-05-06 16:21:52 INFO  RequestMappingHandlerMapping:220 - Mapped "{[/restProxy/**],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.lang.String> foo.bar.web.controllers.RestfulFooBarProxyController.proxyGet(javax.servlet.http.HttpServletRequest)
2015-05-06 16:21:52信息请求映射HandlerMapping:220-将“{[/restProxy/**],methods=[GET],params=[],headers=[],consumes=[],products=[],consumes=[],products=[],custom=[])映射到public org.springframework.http.responseentEntityfoo.bar.web.controllers.RestfulFooBarProxyController.proxyGet(javax.servlet.http.HttpServletRequest)

请求映射中的EL是一种东西吗?我以前从未见过这种情况,所以如果是的话,这对我来说是新的。文档中也是这样:我并不是说你错了,我只是惊讶于它能起作用。我知道可以使用
{…}
@PathVariable
s放置占位符,甚至知道这些占位符可以使用regex。我想我从来没有读过这样一部分:你可以使用EL在你的
@RequestMapping
中插入属性值。Spring开发人员在api中的详细程度让我感到惊讶。
2015-05-06 16:21:52 INFO  RequestMappingHandlerMapping:220 - Mapped "{[/restProxy/**],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.lang.String> foo.bar.web.controllers.RestfulFooBarProxyController.proxyGet(javax.servlet.http.HttpServletRequest)