I am using Spring's @PropertySource
and @ConfigurationProperties
to read the properties from a file. Below are the sample properties:
patterns[0]=\b(test1)\b
patterns[1]=\b(test2)\b
Below is the class that reads these properties:
@Configuration
@PropertySource("classpath:patterns.properties")
@ConfigurationProperties
public class PatternConfig {
private List<String> patterns;
//Getters and Setters
}
This reads the properties as expected and sets the values in patterns
list. However, what I really want to do is, to compile the pattern
before it gets added and then add it into the list of Patterns. E.g. the new list will be
private List<Pattern> patterns;
So, I need to override something which would call Pattern.compile
on string property and return Pattern
object which would then get added into the list. Is it possible?
Create a method in this configuration that returns the list of patterns, annotate it with @Bean, and do the pattern compile within the method.