Skip to content

Commit

Permalink
support loading properties file in unnamed resources module. (#1827)
Browse files Browse the repository at this point in the history
  • Loading branch information
arjenzhou authored Nov 2, 2024
1 parent 64f96f3 commit 662847b
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/main/java/com/zaxxer/hikari/HikariConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.*;
import java.lang.reflect.Modifier;
import java.security.AccessControlException;
import java.sql.Connection;
Expand Down Expand Up @@ -1199,8 +1197,7 @@ else if (value == null) {

private void loadProperties(String propertyFileName)
{
final var propFile = new File(propertyFileName);
try (final var is = propFile.isFile() ? new FileInputStream(propFile) : this.getClass().getResourceAsStream(propertyFileName)) {
try (final var is = openPropertiesInputStream(propertyFileName)) {
if (is != null) {
var props = new Properties();
props.load(is);
Expand All @@ -1215,6 +1212,18 @@ private void loadProperties(String propertyFileName)
}
}

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()
{
final var prefix = "HikariPool-";
Expand Down

0 comments on commit 662847b

Please sign in to comment.