起動時に DB にバックアップされた一連のプロパティを追加する必要があります。全体の動作をテストするために、これから始めました (以下の ds.username プロパティは catalina.properties から取得されます。何も壊れていないことを確認するためだけに存在します):
public class PropertiesInitializer implements ApplicationContextInitializer<ConfigurableWebApplicationContext> {
@Override
public void initialize(ConfigurableWebApplicationContext ctx) {
try {
props.put("hello", "goodbye");
MutablePropertySources propertySources = ctx.getEnvironment().getPropertySources();
propertySources.addFirst(new MapPropertySource("dbProps", props));
}
catch(Exception e) {
e.printStackTrace();
}
}
私は @Controller を持っていて、これをやっています:
@Autowired
Environment env;
@Value( "${hello}" )
public String hello;
@Value( "${ds.username}" )
public String un;
...
したがって、これらを印刷すると、「hello」と「un」は空ですが、env.getProperties は実際には正しい値を返します。
なんで?
ありがとう
ヘラルド・ブランコ