Heim  >  Fragen und Antworten  >  Hauptteil

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

巴扎黑巴扎黑2729 Tage vor628

Antworte allen(2)Ich werde antworten

  • PHPz

    PHPz2017-04-18 10:46:01

    不需要 get set 方法

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

    Antwort
    0
  • PHP中文网

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

    既然你要注入的是整个 properties,那么应该写的是:

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

    而不是

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

    Antwort
    0
  • StornierenAntwort