Missing include a getter for channel list:
@ConfigurationProperties(prefix = "parceiros")
@Component
public class CanaisMapper {
private List<String> canais = new ArrayList<String>();
private void verificaCanal(String canal, Status status){
if(canais.contains(canal)) {
status.setStatus("OK");
}
}
public List<String> getCanais() {
return this.canais;
}
}
Documentation of Spring Boot
Edit
Upgrading to a functional example
Configurationpropertiesdemoapplication.java
package com.example.demo;
import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;
@SpringBootApplication
public class ConfigurationPropertiesDemoApplication {
public static void main(String[] args) {
ConfigurableApplicationContext ctxt = SpringApplication.run(ConfigurationPropertiesDemoApplication.class, args);
ctxt.getBean(ConfigurationPropertiesExample.class).printChannels();
}
@Component
@ConfigurationProperties(prefix = "app")
public class ConfigurationPropertiesExample {
private List<String> channels = new ArrayList<>();
public void printChannels() {
System.out.println(channels);
}
public List<String> getChannels() {
return channels;
}
}
}
application.yaml
app:
channels:
- abc
- cdb
- xyz
Output when uploading the project is from the channel list configured in application.yaml
:
:: Spring Boot :: (v2.1.5.RELEASE)
2019-06-01 18:36:44.618 INFO 1252 --- [ restartedMain] d.ConfigurationPropertiesDemoApplication : Starting ConfigurationPropertiesDemoApplication on DESKTOP-EBSB0DB with PID 1252 (C:\projects\configuration-properties-demo\target\classes started by Norton Gueno in C:\projects\configuration-properties-demo)
2019-06-01 18:36:44.620 INFO 1252 --- [ restartedMain] d.ConfigurationPropertiesDemoApplication : No active profile set, falling back to default profiles: default
2019-06-01 18:36:44.647 INFO 1252 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-06-01 18:36:45.041 INFO 1252 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2019-06-01 18:36:45.057 INFO 1252 --- [ restartedMain] d.ConfigurationPropertiesDemoApplication : Started ConfigurationPropertiesDemoApplication in 0.724 seconds (JVM running for 1.366)
[abc, cdb, xyz]
Possible duplicate of How to make an if by comparing a value with a list in a yml?
– nullptr