search

Home  >  Q&A  >  body text

Spring4 根据类型自动装配属性类型为java.util.Properties

巴扎黑巴扎黑2846 days ago680

reply all(2)I'll reply

  • PHPz

    PHPz2017-04-18 10:46:01

    No need for get set method

    @Value("#{propertiesReader}")
    public Properties props;
    
    @Value("#{propertiesReader['username']}")
    public String username;

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:46:01

    Since you want to inject the entire properties, you should write:

    @Value("#{propertiesReader}")
    public void setProps(Properties props) {
        this.props = props;
    }
    

    instead of

    @Value("#{propertiesReader[username]}")
    

    reply
    0
  • Cancelreply