0

In my class I have:

@Component
public class AwgTekConsumerProperties {

    @Value("${awgtek_topic_consumer.default_thread_pool_size:10}")
    private Integer defaultThreadPoolSize;

    @Value("${awgtek_topic_consumer.default_keep_alive_time:10}")
    private Integer defaultKeepAliveTime;

    ....
}

I would like to retrieve a list of the field values, i.e. ["awgtek_topic_consumer.default_thread_pool_size", "awgtek_topic_consumer.default_keep_alive_time",...]

What I have tried is: Set<String> consumperPropertyNames = FieldUtils .getFieldsListWithAnnotation(AwgTekConsumerProperties.class, Value.class).stream() .map(field -> ((Value) Arrays.stream(field.getDeclaredAnnotations()).filter(a -> a instanceof Value).findFirst().get()).value()) .collect(Collectors.toSet());

But this results in the whole field name, i.e. ["${awgtek_topic_consumer.default_thread_pool_size:10}", "${awgtek_topic_consumer.default_keep_alive_time:10}"..] including Spring EL and defaults. Is there a way to parse out only the field name using Spring utilities or some other elegant way? I tried looking into Spring Expression Language but could not find the way to parse it out, but I probably missed something. Is there a better way than doing String.indexOf etc.?

0 Answers0