首页 > 解决方案 > Spring getAnnotation 没有解析读取的属性文件

问题描述

配置:

for (Method m : objClz.getDeclaredMethods()) {
                if (m.isAnnotationPresent(CountryEnabled.class)) {
                    GetMapping annotation1 = m.getAnnotation(GetMapping.class);
                    log.info("{}",annotation1.value());
                }
            }

控制器:

@GetMapping("${bean.get.endpoint}")
    public ResponseEntity getGreeting(@PathVariable String version){
        return versionController.findVersionHandler("${bean.get.endpoint}", version, HttpMethod.GET);
    }

道具文件:

server.port=8081

bean.get.endpoint=/{version}/greeting
bean.get.endpoint.message=/{version}/greeting/{message}
bean.get.endpoint.message.secondmessage=/{version}/greeting/{message}/{secondmessage}
bean.post.endpoint.message=/{version}/greeting

从配置文件记录:

2020-08-04 22:18:57.492  INFO 21096 --- [  restartedMain] c.e.b.a.country.CountryEnabledConfig     : [${bean.get.endpoint}]

似乎正在阅读,[${bean.get.endpoint}]而不是实际值/{version}/greeting,有没有办法解决它?

标签: springspring-annotations

解决方案


推荐阅读