Is there an easy way to read custom files from the META-INF directory in SpringBoot applications?
Usually, the META-INF directory is used for files with the same name in different JARs. SpringBoot uses this mechanism itself for various frameworks (eg. /META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports).
I tried:
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.core.io.ClassPathResource;
[...]
public static MyMetaData loadMyMetaData (Class<?> type) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
try (InputStream is = new ClassPathResource("/META-INF/mysystem/myMetaData.json", type).getInputStream()) {
return objectMapper.readValue(is, MyMetaData.class);
}
}
But the second file in the second JAR is hidden as it would be with any other resource.
So is there an easy way in SpringBoot that when I pass class A of a.jar I get the myMetaData.json of a.jar and when I pass class B of b.jar I get the myMetaData.json of b.jar?