java - How can I get the bean of a property file in Spring-Boot? -
i need play around keys of property file. key dynamic, need bean of property file mentioned below current running spring application.
spring configuration:
<bean id="multiplewriterlocations" class="org.springframework.beans.factory.config.propertiesfactorybean"> <property name="ignoreresourcenotfound" value="true" /> <property name="locations"> <list> <value>classpath:writerlocations.properties</value> <value>file:config/writerlocations.properties</value> </list> </property> </bean>
java code:
properties prop = appcontext.getbean("multiplewriterlocations")
i need same properties bean instance in spring-boot. need transform existing spring application spring-boot without changing functionalities.
one way properties file value using @propertysource(), in case need key name. in case, key name not known , need fetch keyset properties bean.
you can use @importresource("classpath:config.xml")
config.xml
contains propertiesfactorybean
above, , autowire @springbootapplication
or @configuration
class.
@springbootapplication @importresource("classpath:config.xml") public class app { public app(propertiesfactorybean multiplewriterlocations) throws ioexception { // access properties populated writerlocations.properties properties properties = multiplewriterlocations.getobject(); system.out.println(properties); } public static void main(string[] args) { springapplication.run(app.class, args); } }
Comments
Post a Comment