Reputation: 711
I'm trying to make some kind of all Environment properties validator. What I want is just take all properties from Environment.
(I already found this here: Spring: access all Environment properties as a Map or Properties object)
Next on all properties I want to make environment.getProperty(x) And If some properties are null then just I want add them and throw as message of Excpetion.
That works pretty well, but.. Checking of all dependencies is performing after logger initialization and after jpa/hibernate initialization.
Can I somehow get with my "validation mechanizm" before that actions and with access to Environment bean? Or maybe there is way to take Environment without running application?
Upvotes: 0
Views: 171
Reputation: 105
a)
Map<String, String> notNullPropertiesMap = yourPropertiesMap.entrySet()
.stream()
.filter(entry -> Objects.nonNull(entry.getValue()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
b)
Map<Boolean, List<Map.Entry<Object, Object>>> splitPropertiesMap = yourPropertiesMap.entrySet()
.stream()
.collect(Collectors.partitioningBy(entry -> Objects.nonNull(entry.getValue())));
In second example splitPropertiesMap.get(Boolean.TRUE) will return you list of all not NULL properties Map.
Anyway I hope it'll help you to simplify your code.
Upvotes: 1