@@ -52,38 +52,48 @@ class HikariCPDataSource {
5252
5353 static {
5454 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 );
5858
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 ));
6262
6363 config .setMaximumPoolSize (
64- Integer .parseInt (hikariJdbcProperties . getProperty ( " hikaricp.maxPoolSize" )));
64+ Integer .parseInt (getEnvOrConfigProperty ( "vss. hikaricp.maxPoolSize", applicationProperties )));
6565 config .setMinimumIdle (
66- Integer .parseInt (hikariJdbcProperties . getProperty ( " hikaricp.minimumIdle" )));
66+ Integer .parseInt (getEnvOrConfigProperty ( "vss. hikaricp.minimumIdle", applicationProperties )));
6767 config .setConnectionTimeout (
68- Long .parseLong (hikariJdbcProperties . getProperty ( " hikaricp.connectionTimeout" )));
68+ Long .parseLong (getEnvOrConfigProperty ( "vss. hikaricp.connectionTimeout", applicationProperties )));
6969 config .setIdleTimeout (
70- Long .parseLong (hikariJdbcProperties . getProperty ( " hikaricp.idleTimeout" )));
70+ Long .parseLong (getEnvOrConfigProperty ( "vss. hikaricp.idleTimeout", applicationProperties )));
7171 config .setMaxLifetime (
72- Long .parseLong (hikariJdbcProperties . getProperty ( " hikaricp.maxLifetime" )));
72+ Long .parseLong (getEnvOrConfigProperty ( "vss. hikaricp.maxLifetime", applicationProperties )));
7373
7474 config .addDataSourceProperty ("cachePrepStmts" ,
75- hikariJdbcProperties . getProperty ( " hikaricp.cachePrepStmts" ));
75+ getEnvOrConfigProperty ( "vss. hikaricp.cachePrepStmts", applicationProperties ));
7676 config .addDataSourceProperty ("prepStmtCacheSize" ,
77- hikariJdbcProperties . getProperty ( " hikaricp.prepStmtCacheSize" ));
77+ getEnvOrConfigProperty ( "vss. hikaricp.prepStmtCacheSize", applicationProperties ));
7878 config .addDataSourceProperty ("prepStmtCacheSqlLimit" ,
79- hikariJdbcProperties . getProperty ( " hikaricp.prepStmtCacheSqlLimit" ));
79+ getEnvOrConfigProperty ( "vss. hikaricp.prepStmtCacheSqlLimit", applicationProperties ));
8080
8181 dataSource = new HikariDataSource (config );
8282 } catch (IOException e ) {
83- throw new RuntimeException ("Unable to read hikariJdbcProperties from resources" );
83+ throw new RuntimeException ("Unable to read application.properties from resources" );
8484 }
8585 }
8686
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+
8797 private HikariCPDataSource () {
8898 }
8999}
0 commit comments