Java 集合不包含';t在弹簧靴中工作

Java 集合不包含';t在弹簧靴中工作,java,spring-boot,Java,Spring Boot,Set包含return false,即使它包含对象 String str = "name"; MyProperties.getFileProperties().contains(str); // returns false // MyProperties.getFileProperties() value is [name, name1] MyProperties在另一个类中填充 @ConfigurationProperties("prop")

Set包含return false,即使它包含对象

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

// MyProperties.getFileProperties() value is [name, name1]
MyProperties在另一个类中填充

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

我猜您的属性有一个字符串
“name,name1”
,而不是两个字符串
“name”
“name1”
。请尝试按以下方式格式化yaml:

file-properties:
  - name
  - name1

这毫无意义-您不能使用布尔值设置
set
字段…我相信它还支持
文件属性:name,name1
,但将它们组合使用会破坏列表处理
file-properties:
  - name
  - name1