使用@Value 访问 Micronaut application.yml
Micronaut access application.yml with @Value
你好,我有一个 micronaut 应用程序 application.yml
micronaut:
application:
name: hello-world
pref:
msg: Luca
在 class 中我想设置一个变量的值 :
@Value("${pref.msg}")
private lateinit var text : String
但是 IDE 抱怨说注释参数必须是编译时常量
我也试过
@Property(name = "pref.msg" )
但它编译但不读取 属性。
有人可以帮忙吗?
您需要使用反斜杠转义 $
字符,因为 kotlin 使用 dollar 来表示模板。
@Value("${pref.msg}")
你好,我有一个 micronaut 应用程序 application.yml
micronaut:
application:
name: hello-world
pref:
msg: Luca
在 class 中我想设置一个变量的值 :
@Value("${pref.msg}")
private lateinit var text : String
但是 IDE 抱怨说注释参数必须是编译时常量
我也试过
@Property(name = "pref.msg" )
但它编译但不读取 属性。
有人可以帮忙吗?
您需要使用反斜杠转义 $
字符,因为 kotlin 使用 dollar 来表示模板。
@Value("${pref.msg}")