gpt4 book ai didi

Java Spring : How to use `@Value` annotation to inject an `Environment` property?

转载 作者:IT老高 更新时间:2023-10-28 13:44:07 24 4
gpt4 key购买 nike

使用诸如

之类的构造
@Component
public class SomeClass {

@Inject
private Environment env;

private String key;


@PostConstruct
private void init() {

key = env.getProperty("SOME_KEY_PROPERTY");

}

....
}

可以为某些字段分配某些属性。

有没有更短更简洁的形式来做到这一点?

最佳答案

@Component
public class SomeClass {

@Value("#{environment.SOME_KEY_PROPERTY}")
private String key;

....
}

关于Java Spring : How to use `@Value` annotation to inject an `Environment` property?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14617181/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com