Spring boot允许使用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@email.com"
String name = "User Name";
String key=env.getProperty("myapp.configured.key", email, name);
System.out.println(key);
输出将是这样的:
This is your email > email@email.com And this is your name > User Name
答案 0 :(得分:2)
如果您的email
和name
也是配置密钥,您可以在邮件中引用它们(但这有点奇怪)
myapp.configured.email: email@example.com
myapp.configured.name: John Smith
myapp.configured.key: This is your email > ${myapp.configured.email} And this is your name > ${myapp.configured.name}
Environment
没有这样的API和Spring Boot用户,你甚至不应该触摸那些东西(检查@ConfigurationProperties
是否有类型安全绑定配置)。