Skip to content

Commit 662847b

Browse files
authored
support loading properties file in unnamed resources module. (#1827)
1 parent 64f96f3 commit 662847b

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

src/main/java/com/zaxxer/hikari/HikariConfig.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
import javax.naming.InitialContext;
2727
import javax.naming.NamingException;
2828
import javax.sql.DataSource;
29-
import java.io.File;
30-
import java.io.FileInputStream;
31-
import java.io.IOException;
29+
import java.io.*;
3230
import java.lang.reflect.Modifier;
3331
import java.security.AccessControlException;
3432
import java.sql.Connection;
@@ -1199,8 +1197,7 @@ else if (value == null) {
11991197

12001198
private void loadProperties(String propertyFileName)
12011199
{
1202-
final var propFile = new File(propertyFileName);
1203-
try (final var is = propFile.isFile() ? new FileInputStream(propFile) : this.getClass().getResourceAsStream(propertyFileName)) {
1200+
try (final var is = openPropertiesInputStream(propertyFileName)) {
12041201
if (is != null) {
12051202
var props = new Properties();
12061203
props.load(is);
@@ -1215,6 +1212,18 @@ private void loadProperties(String propertyFileName)
12151212
}
12161213
}
12171214

1215+
private InputStream openPropertiesInputStream(String propertyFileName) throws FileNotFoundException {
1216+
final var propFile = new File(propertyFileName);
1217+
if (propFile.isFile()) {
1218+
return new FileInputStream(propFile);
1219+
}
1220+
var propertiesInputStream = this.getClass().getResourceAsStream(propertyFileName);
1221+
if (propertiesInputStream == null) {
1222+
propertiesInputStream = this.getClass().getClassLoader().getResourceAsStream(propertyFileName);
1223+
}
1224+
return propertiesInputStream;
1225+
}
1226+
12181227
private String generatePoolName()
12191228
{
12201229
final var prefix = "HikariPool-";

0 commit comments

Comments
 (0)