简体   繁体   中英

Binding spring boot application properties to java.util.properties

I am creating a spring-boot application which also creates bean for one of the classes of an external lib, this external java bean needs java.util.properties as one of the constructor parameter. Although I can use configurationPropeties with prefix to read properties from the spring boot loaded property file and convert it to java.util.properties.However, I don't want any additional prefix in the property file. is there any other way where I can convert the spring-boot loaded env or property source to java.util.properties

here is the code for reference

@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());
    }
}

the above code work nicely, but I need to add an unnecessary prefix to the properties for conversion. could someone suggest any other approach apart from adding prefix to the propeties

Take a look at this documentation. It explains property binding techniques used in spring-boot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM