私はapplication.properties
からプロパティをフェッチするConfiguration.classを持っています。spring-bootでは、spring beanなしでプロパティを取得できますか?
@Component
public class Configuration {
@Value("${someValue}")
public String someValue;
}
私は、プロパティを必要としFetcher
と呼ばれる別のクラスを、持っています。もちろん
class Fetcher {
@Autowired
private Configuration configuration;
public void doSomethingWithSomeValue() {
System.out.println(configuration.someValue);
}
}
Fetcher
は春の豆(私はそれに@Component
/@Service
/@Repository
を追加しませんでしたが)ではないので、上記のコードは失敗します。私の質問は、をFetcher
に入れることができますか?
多分、設定ファイルを地図に読み込んでそこから取得しますか? –
https://stackoverflow.com/a/18486178/1032167とhttps://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/ApplicationContextAware.htmlをご覧ください – varren