彈簧啓動允許使用YAML使用參數化鍵嗎? parametred關鍵的彈簧啓動YAML配置:參數鍵
例子:
myapp.configured.key: This is your email > {0} And this is your name > {1}
在我的Java類,我想要做一些事情是這樣的:
@Inject
private Environment env;//import org.springframework.core.env.Environment;
String email = "[email protected]"
String name = "User Name";
String key=env.getProperty("myapp.configured.key", email, name);
System.out.println(key);
和外認沽將是這樣的:
This is your email > [email protected] And this is your name > User Name
如果你能做'String key = String.format(env.getProperty(「myapp.configured.key」),email,name);'(假設你可以改變你的佔位符爲'%s ') – kryger
因爲在Spring中使用MessageSource(org.springframework.context.MessageSource),我們可以做一些類似於上面的事情(比較類型)。但看起來好的替代方法;)。謝謝 – BOSS