3

I'm trying to retrieve the configuration from following yaml where I have some nested arrays

ems:
  filtered-queue:
    - filter-regular-expressions:
       - AAA*MD1
       - AAA*MD2
      destination-queue-names:
       - ems.omie1
       - ems.aws1   
    - filter-regular-expressions:
       - BBB*MD1
       - BBB*MD2
      destination-queue-names:
       - ems.omie2
       - ems.aws2

I've double checked and there a no indentation issues. The ConfigServer is reading the file properly.

My current code to retrieve the configuration is as follows

import java.util.ArrayList;
import java.util.List;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties(prefix="ems")
public class FilteredQueueConfiguration {
    @NestedConfigurationProperty
    private List<FilteredQueue> filteredQueue = new ArrayList<>();


    @Data
    public class FilteredQueue {
        private List<String> filterRegularExpressions = new ArrayList<>();
        private List<String> destinationQueuenames = new ArrayList<>();
    }   
}

In my main class I have the @EnableConfigurationProperties(FilteredQueueConfiguration.class) annotation

I have always the same exception abound Binding to target ... failed. Any clue of what I'm doing wrong?

0

1 Answer 1

1

The inner class FilteredQueue should be static class, see the Type-safe Configuration Properties

import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties(prefix="ems")
public class FilteredQueueConfiguration {
    @NestedConfigurationProperty
    private List<FilteredQueue> filteredQueue = new ArrayList<>();


@Data
public static class FilteredQueue {
    private List<String> filterRegularExpressions = new ArrayList<>();
    private List<String> destinationQueuenames = new ArrayList<>();
     }   
 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.