Spring のEnvironment プロパティ抽象化からプロパティに動的にアクセスしようとしています。
プロパティ ファイルを次のように宣言します。
<context:property-placeholder
location="classpath:server.common.properties,
classpath:server.${my-environment}.properties" />
プロパティ ファイルserver.test.propertiesで、次のように定義します。
myKey=foo
次に、次のコードを指定します。
@Component
public class PropertyTest {
@Value("${myKey}")
private String propertyValue;
@Autowired
private PropertyResolver propertyResolver;
public function test() {
String fromResolver = propertyResolver.getProperty("myKey");
}
}
このコードを実行すると、最終的にpropertyValue='foo', but fromResolver=null;になります。
受信propertyValueは、プロパティが読み取られていることを示します (コードの他の部分からこれを知っています)。ただし、それらを動的に検索しようとすると失敗します。
なんで?を使用せずにプロパティ値を動的に検索するにはどうすればよい@Valueですか?