将 属性 值注入注释字段

Inject property value into annotation field

我正在开发我的休息 API 我想要一个端点的动态列表。我正在使用以下方法:

@Controller("/")
public class Resource {

    @PostMapping(path = {"request1", "request2"})
    public Mono<ResponseEntity> postData(ServerHttpRequest request) {
        return Mono.fromSupplier(() -> ResponseEntity.ok().build());
    }
}

所以我想知道是否可以从属性中动态检索 PostMapping 的路径字段的值?

提前致谢

试试这个:

@RestController
public class Resource {
    @Value("${helloworld.endpoints}") String endpoints = "";

    @GetMapping(value = "/maybe/{wildcard}")
    public Mono<ResponseEntity> post(@PathVariable(value = "wildcard") String path) {
        boolean ok = Arrays.asList(endpoints.split(";")).contains(path);
        if (ok)
            return Mono.fromSupplier(() -> ResponseEntity.ok().build());
        else
            return Mono.fromSupplier(() -> ResponseEntity.notFound().build());
    }
}

application.properties:

helloworld.endpoints=request1;request2;request3