Spring Util:Properties Injection via Annotations into a bean

前端 未结 5 812
轻奢々
轻奢々 2020-12-23 21:19

If I have 2 .properties files setup in my Spring XML as so:



        
5条回答
  •  遥遥无期
    2020-12-23 21:34

    @Autowired
    @Qualifier("serverProperties")
    private Properties serverProperties;
    @Autowired
    @Qualifier("someConfig")
    private Properties otherProperties;
    

    or

    @Resource(name = "serverProperties")
    private Properties serverProperties;
    @Resource(name = "someConfig")
    private Properties otherProperties;
    

    Typically, @Autowired is used for by-type autowiring in Spring, and @Resource is used for by-name. @Autowired+@Qualifier can double as by-name autowiring, but it's really meant for by-type autowiring with the ability to fine-tune the type.

提交回复
热议问题