@@ -52,38 +52,48 @@ class HikariCPDataSource {
52
52
53
53
static {
54
54
try (InputStream input = HikariCPDataSource .class .getClassLoader ()
55
- .getResourceAsStream ("hikariJdbc .properties" )) {
56
- Properties hikariJdbcProperties = new Properties ();
57
- hikariJdbcProperties .load (input );
55
+ .getResourceAsStream ("application .properties" )) {
56
+ Properties applicationProperties = new Properties ();
57
+ applicationProperties .load (input );
58
58
59
- config .setJdbcUrl (hikariJdbcProperties . getProperty ( " jdbc.url" ));
60
- config .setUsername (hikariJdbcProperties . getProperty ( " jdbc.username" ));
61
- config .setPassword (hikariJdbcProperties . getProperty ( " jdbc.password" ));
59
+ config .setJdbcUrl (getEnvOrConfigProperty ( "vss. jdbc.url", applicationProperties ));
60
+ config .setUsername (getEnvOrConfigProperty ( "vss. jdbc.username", applicationProperties ));
61
+ config .setPassword (getEnvOrConfigProperty ( "vss. jdbc.password", applicationProperties ));
62
62
63
63
config .setMaximumPoolSize (
64
- Integer .parseInt (hikariJdbcProperties . getProperty ( " hikaricp.maxPoolSize" )));
64
+ Integer .parseInt (getEnvOrConfigProperty ( "vss. hikaricp.maxPoolSize", applicationProperties )));
65
65
config .setMinimumIdle (
66
- Integer .parseInt (hikariJdbcProperties . getProperty ( " hikaricp.minimumIdle" )));
66
+ Integer .parseInt (getEnvOrConfigProperty ( "vss. hikaricp.minimumIdle", applicationProperties )));
67
67
config .setConnectionTimeout (
68
- Long .parseLong (hikariJdbcProperties . getProperty ( " hikaricp.connectionTimeout" )));
68
+ Long .parseLong (getEnvOrConfigProperty ( "vss. hikaricp.connectionTimeout", applicationProperties )));
69
69
config .setIdleTimeout (
70
- Long .parseLong (hikariJdbcProperties . getProperty ( " hikaricp.idleTimeout" )));
70
+ Long .parseLong (getEnvOrConfigProperty ( "vss. hikaricp.idleTimeout", applicationProperties )));
71
71
config .setMaxLifetime (
72
- Long .parseLong (hikariJdbcProperties . getProperty ( " hikaricp.maxLifetime" )));
72
+ Long .parseLong (getEnvOrConfigProperty ( "vss. hikaricp.maxLifetime", applicationProperties )));
73
73
74
74
config .addDataSourceProperty ("cachePrepStmts" ,
75
- hikariJdbcProperties . getProperty ( " hikaricp.cachePrepStmts" ));
75
+ getEnvOrConfigProperty ( "vss. hikaricp.cachePrepStmts", applicationProperties ));
76
76
config .addDataSourceProperty ("prepStmtCacheSize" ,
77
- hikariJdbcProperties . getProperty ( " hikaricp.prepStmtCacheSize" ));
77
+ getEnvOrConfigProperty ( "vss. hikaricp.prepStmtCacheSize", applicationProperties ));
78
78
config .addDataSourceProperty ("prepStmtCacheSqlLimit" ,
79
- hikariJdbcProperties . getProperty ( " hikaricp.prepStmtCacheSqlLimit" ));
79
+ getEnvOrConfigProperty ( "vss. hikaricp.prepStmtCacheSqlLimit", applicationProperties ));
80
80
81
81
dataSource = new HikariDataSource (config );
82
82
} catch (IOException e ) {
83
- throw new RuntimeException ("Unable to read hikariJdbcProperties from resources" );
83
+ throw new RuntimeException ("Unable to read application.properties from resources" );
84
84
}
85
85
}
86
86
87
+ // Retrieves the value of a specified property, first checking environment variables,
88
+ // then falling back to provided configuration properties if the environment variable is not set.
89
+ private static String getEnvOrConfigProperty (String key , Properties hikariJdbcProperties ) {
90
+ String propertyValue = System .getenv (key );
91
+ if (StringUtils .isBlank (propertyValue )) {
92
+ propertyValue = hikariJdbcProperties .getProperty (key );
93
+ }
94
+ return propertyValue ;
95
+ }
96
+
87
97
private HikariCPDataSource () {
88
98
}
89
99
}
0 commit comments