How can I use with spring kafka(without sboot) for SSL configuration a relative/classpath path for specifying location of truststore for example?
It works only when absolute path is provided.
Suprisingly it works with relative path(within jar) when runnig with spring boot..
The file is read by Kafka, not Spring.
Kafka has no knowledge of Spring's classpath resource abstraction.
I think you are mistaken about boot; it only works there if the jar is exploded; boot has this code in KafkaProperties
...
map.from(this::getTrustStoreLocation).as(this::resourceToPath)
.to(properties.in(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG));
...
private String resourceToPath(Resource resource) {
try {
return resource.getFile().getAbsolutePath();
}
catch (IOException ex) {
throw new IllegalStateException(
"Resource '" + resource + "' must be on a file system", ex);
}
}
To use a truststore from within a jar, you would need to first copy it to a filesystem (e.g. /tmp
) before starting the application context.