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 protected] /cdn-cgi/l/email-protection"
String name = "User Name";
String key=env.getProperty("myapp.configured.key", email, name);
System.out.println(key);
输出将是这样的:
This is your email > [email protected] /cdn-cgi/l/email-protection And this is your name > User Name
If your email
and name
也是配置键,您可以在消息中引用它们(但这有点奇怪)
myapp.configured.email: [email protected] /cdn-cgi/l/email-protection
myapp.configured.name: John Smith
myapp.configured.key: This is your email > ${myapp.configured.email} And this is your name > ${myapp.configured.name}
The Environment
没有这样的 API,作为 Spring Boot 用户,你甚至不应该碰那些东西(检查@ConfigurationProperties
用于配置的类型安全绑定)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)