mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-12 07:02:10 +00:00
DATAES-237 - path-configuration fails to load configs from inside jars
This commit is contained in:
parent
6535caff8a
commit
1cf18a4a50
@ -17,9 +17,7 @@ package org.springframework.data.elasticsearch.client;
|
|||||||
|
|
||||||
import static org.elasticsearch.node.NodeBuilder.*;
|
import static org.elasticsearch.node.NodeBuilder.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.client.node.NodeClient;
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
@ -29,7 +27,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NodeClientFactoryBean
|
* NodeClientFactoryBean
|
||||||
@ -83,11 +80,11 @@ public class NodeClientFactoryBean implements FactoryBean<NodeClient>, Initializ
|
|||||||
|
|
||||||
private Settings loadConfig() {
|
private Settings loadConfig() {
|
||||||
if (StringUtils.isNotBlank(pathConfiguration)) {
|
if (StringUtils.isNotBlank(pathConfiguration)) {
|
||||||
try {
|
InputStream stream = getClass().getClassLoader().getResourceAsStream(pathConfiguration);
|
||||||
return Settings.builder().loadFromPath(Paths.get(new ClassPathResource(pathConfiguration).getURI())).build();
|
if (stream != null) {
|
||||||
} catch (IOException e) {
|
return Settings.builder().loadFromStream(pathConfiguration, getClass().getClassLoader().getResourceAsStream(pathConfiguration)).build();
|
||||||
logger.error(String.format("Unable to read node configuration from file [%s]", pathConfiguration), e);
|
|
||||||
}
|
}
|
||||||
|
logger.error(String.format("Unable to read node configuration from file [%s]", pathConfiguration));
|
||||||
}
|
}
|
||||||
return Settings.builder().build();
|
return Settings.builder().build();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user