簡體   English   中英

來自屬性文件的java.util.Properties類型的Spring bean

[英]Spring bean of type java.util.Properties from properties file

我必須使用的一種庫要求將java.util.Properties類型對象作為參數。 我想從Spring的屬性文件中獲取值。

因此,我的問題是-在Spring中,僅使用“ Java Config”(無XML)獲得諸如bean之類的對象的最佳方法是什么?

你可以試試這個

class B1 {
    B1(Properties props) {
        //s
    }
}

@Configuration
class Config {

    @Bean
    B1 b1() {
        Properties props = new Properties();
        // load...
        return new B1(props);
    }

...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM