繁体   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