1

After reading couple of answers on stackoverflow. I tried to implement the way it was recommended but i am still not getting string list in my component.

Here is my application.yml file

appName:
  db:
    host: localhost
    username: userX
    password: passX
    driverClassName: org.postgresql.Driver
  shipment:
    providers:
      supported1:
        - one
        - two

And my component class is

@Component
@ConfigurationProperties(prefix = "appName.shipment.providers")
public class ProviderUtil {
  List<String> supported1;

  /* This class has other util methods as well */
}

Here, I am expecting that supported1 would have list of strings one and two but it is null. Can someone help what is going on here and how to resolve it ?

Community
  • 1
  • 1
Em Ae
  • 7,519
  • 22
  • 73
  • 143

2 Answers2

1

Do you have spring-boot-configuration-processor dependency on your classpath? Try to look here

And also change your bean from @Component to @Configuration

rajadilipkolli
  • 3,319
  • 1
  • 24
  • 47
bilak
  • 3,668
  • 2
  • 28
  • 61
  • Yup, i have added it exactly the way it is mentioned in the docs. with `optional` value set to `true` and I used `component` because of this reponse >> http://stackoverflow.com/questions/26699385/spring-boot-yaml-configuration-for-a-list-of-strings ... That being said, I have tried both with `configuration` and `component` but no luck – Em Ae Jul 27 '16 at 17:08
  • Try to share your code to see if we can help you somehow. – bilak Jul 27 '16 at 17:15
  • I figured out the issue. I hadn't provided the getters/setters. I had made the field public and i thought it would work – Em Ae Jul 27 '16 at 19:09
0

I followed this post and added the getters and setters for the list. It worked out for me.

Code:

@Service("testservice")
@ConfigurationProperties(prefix="es")
public class TestService {

     @Value("${url.endPoint}")
     private String endpointUrl;

     private List<String> scope;
    public List<String> getScope() {
        return scope;
    }

    public void setScope(List<String> scope) {
        this.scope = scope;
    }
..
}
Emma
  • 26,487
  • 10
  • 35
  • 65
SPS
  • 21
  • 3