简体   繁体   English

在注解中注入Spring属性列表

[英]Inject list of Spring properties in annotation

I want to map REST endpoints dynamically to a RestController. 我想将REST端点动态映射到RestController。 I'd like to configure the endpoints as properties. 我想将端点配置为属性。

My RestController looks like this 我的RestController看起来像这样

@RestController
public class MyRestController {
    }

    @PutMapping("#{'${mapping}'.split(',')}")
    public String fooMapping(@RequestHeader MultiValueMap<String, String> headers, HttpServletRequest request) throws URISyntaxException {

        return "foo";
    }
}

The application.properties look like this application.properties看起来像这样

mapping=/mapping1,/mapping2,/mapping3

How do I inject the comma separated list into the annotation? 如何将逗号分隔的列表注入注释中? The following hard-coded method does work. 以下硬编码方法确实有效。

@PutMapping(value = {"/mapping1", "/mapping2", "/mapping3"})

Unfortunately, SpEL expressions works only with @Value annotation, but don't seems to work with @RequestMapping and related annotations. 不幸的是,SpEL表达式仅适用于@Value批注,但似乎不适用于@RequestMapping和相关批注。 @RequestMapping only supports placeholders from properties. @RequestMapping仅支持属性中的占位符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM