es9*_*s97 1 spring yaml spring-boot
在 application.yml 文件中我有以下变量
spring:
application:
name: LOCATION-SERVICE
Run Code Online (Sandbox Code Playgroud)
该名称是大写的,但我希望它在以下变量中变为小写:
server:
servlet:
context-path: /api/v1/${spring.application.name}
Run Code Online (Sandbox Code Playgroud)
我知道我可以将应用程序名称更改为小写字母,但我宁愿不这样做,以免弄乱应用程序的其余部分。
是否可以通过其他方式将其变为小写,如果可以,我该怎么做?
要调用方法,您需要使用全功能表达式,即#{...}. 表达式内的占位符可以这样写:
#{'${spring.application.name}'.toLowerCase()}
Run Code Online (Sandbox Code Playgroud)
但是,Spring Boot 似乎不允许在配置文件中使用 SpEL,如下所示:
最后,虽然您可以在 @Value 中编写 SpEL 表达式,但此类表达式不会从应用程序属性文件中进行处理。
| 归档时间: |
|
| 查看次数: |
5681 次 |
| 最近记录: |