简体   繁体   中英

Set Contains doesn't works in Spring Boot

Set Contains return false even though it contains the object

 String str = "name";
 
 MyProperties.getFileProperties().contains(str); // returns false

// MyProperties.getFileProperties() value is [name, name1]

MyProperties is populated in another class

@ConfigurationProperties("prop")
@Configuration
@Getter
@Setter
public class MyProperties {
    
    
    private Set<String> fileProperties;
    
    
    public void setFileProperties(Set<String>fileProperties) {
        this.fileProperties= fileProperties;
    }
...
}

And the property in added using.yml file as

prop:
  ...
  file-properties: 
    - name, name1

I guess your properties have one string "name, name1" instead of two strings "name" , "name1" . Try format your yaml this way:

file-properties:
  - name
  - name1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM