将spring boot应用程序的属性绑定到java.util.properties。

问题描述 投票:0回答:1

我正在创建一个spring-boot应用程序,它也为一个外部lib的一个类创建bean,这个外部java bean需要java.util.properties作为构造函数的参数之一。虽然我可以使用configurationPropeties加前缀从spring boot加载的属性文件中读取属性,并将其转换为java.util.properties.但是,我不希望在属性文件中出现任何额外的前缀,有没有其他方法可以将spring-boot加载的env或属性源转换为java.util.properties呢?

以下是代码,供参考

@Configuration

public class AppConfig {

@ConfigurationProperties(prefix = "some.prefix")
@Bean
public Properties getProperties() {
    return new Properties();
}


@Bean
public ExternalClass externalClass() throws ConfigException {

    return ExternalClass.getInstance(getProperties());
}

}

上面的代码工作得很好,但我需要添加一个不必要的前缀到属性的转换.有人能建议任何其他的方法,除了添加前缀到propeties

java spring-boot properties-file
1个回答
0
投票

请看一下 这个 文档,它解释了spring-boot中使用的属性绑定技术。它解释了spring-boot中使用的属性绑定技术。

© www.soinside.com 2019 - 2024. All rights reserved.