I am trying to load a yml file with the following element into an object in a test class
yml file name is application-acl-config.yml and there are more yml files in the folder. I assume spring boot merges all of them into one when the application starts.
yml file in resources of main folder:
logicalClientIdentifiers:
- applicationIdentifier:
applicationId: x
logicalClientIds:
- x
- applicationIdentifier:
applicationId: y
logicalClientIds:
- y
code in main folder for pojo class:
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "logicalClientIdentifiers")
public class LogicalClientIdentifiers{
private class ApplicationIdentifier {
private String applicationId;
private List<String> logicalClientIds;
public String getApplicationId() {
return applicationId;
}
public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}
public List<String> getLogicalClientIds() {
return logicalClientIds;
}
public void setLogicalClientIds(List<String> logicalClientIds) {
this.logicalClientIds = logicalClientIds;
}
}
private List<ApplicationIdentifier> applicationIdentifiers;
public List<ApplicationIdentifier> getApplicationIdentifiers() {
return applicationIdentifiers;
}
public void setApplicationIdentifiers(List<ApplicationIdentifier> applicationIdentifiers) {
this.applicationIdentifiers = applicationIdentifiers;
}
}
test code in test folder:
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = LogicalClientIdentifiers.class, initializers = ConfigFileApplicationContextInitializer.class)
public class ChannelAuthorizationTest {
@Autowired
LogicalClientIdentifiers applicationAclConfigProps;
@Test
public void test(){
System.out.println();
}
}
I am getting this exception:
`Caused by: org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'logicalClientIdentifiers': Could not bind properties to 'LogicalClientIdentifiers' : prefix=logicalClientIdentifiers, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.source.InvalidConfigurationPropertyNameException: Configuration property name 'logicalClientIdentifiers' is not` valid
I believe I am not creating the pojo properly to parse the yml file or the yml file is not being referenced properly.
question from:
https://stackoverflow.com/questions/66050253/getting-a-binding-property-exception-when-loading-the-yml-file-into-an-object 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…