Spring JavaConfig for java.util.Properties field

后端 未结 6 2066
面向向阳花
面向向阳花 2021-02-13 02:07


Can you please tell me how to use Spring Javaconfig to directly load/autowire a properties file to a java.util.Properties field?

Thanks!

Later edit - st

6条回答
  •  感情败类
    2021-02-13 02:32

    There is also this approach for injecting properties directly using xml configurations. The context xml has this

    
    

    and the java class just uses

    @javax.annotation.Resource
    private Properties myProps;
    

    Voila!! it loads. Spring uses the 'id' attribute in xml to bind to the name of variable in your code.

提交回复
热议问题