support loading properties file in unnamed resources module. (#1827)

pull/2238/head
Zhou Yang 3 months ago committed by GitHub
parent 64f96f350c
commit 662847bd76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -26,9 +26,7 @@ import org.slf4j.LoggerFactory;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.naming.NamingException; import javax.naming.NamingException;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.io.File; import java.io.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.security.AccessControlException; import java.security.AccessControlException;
import java.sql.Connection; import java.sql.Connection;
@ -1199,8 +1197,7 @@ public class HikariConfig implements HikariConfigMXBean
private void loadProperties(String propertyFileName) private void loadProperties(String propertyFileName)
{ {
final var propFile = new File(propertyFileName); try (final var is = openPropertiesInputStream(propertyFileName)) {
try (final var is = propFile.isFile() ? new FileInputStream(propFile) : this.getClass().getResourceAsStream(propertyFileName)) {
if (is != null) { if (is != null) {
var props = new Properties(); var props = new Properties();
props.load(is); props.load(is);
@ -1215,6 +1212,18 @@ public class HikariConfig implements HikariConfigMXBean
} }
} }
private InputStream openPropertiesInputStream(String propertyFileName) throws FileNotFoundException {
final var propFile = new File(propertyFileName);
if (propFile.isFile()) {
return new FileInputStream(propFile);
}
var propertiesInputStream = this.getClass().getResourceAsStream(propertyFileName);
if (propertiesInputStream == null) {
propertiesInputStream = this.getClass().getClassLoader().getResourceAsStream(propertyFileName);
}
return propertiesInputStream;
}
private String generatePoolName() private String generatePoolName()
{ {
final var prefix = "HikariPool-"; final var prefix = "HikariPool-";

Loading…
Cancel
Save