Giriş
@ManagedResource anotasyonu sınıfa yazılır. @ManagedOperation anotasyonu sınıfın metoduna yazılır
@ManagedResource anotasyonu sınıfa yazılır. @ManagedOperation anotasyonu sınıfın metoduna yazılır
import com.zaxxer.hikari.HikariDataSource;
Bu sınıf HikariConfig'den kalıttığı için hem setter() metodlar sunuyor hem de HikariConfig alan bir contructor sunuyor.@Bean
public HikariDataSource dataSource() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(databaseUrl);
config.setUsername(username);
config.setPassword(password);
config.setDriverClassName(driverClassName);
config.setConnectionTimeout(connectionTimeout);
config.setIdleTimeout(idleTimeout);
config.setMaximumPoolSize(maxpoolSize);
config.setMaxLifetime(maxLifeTime);
config.setMinimumIdle(minIdleConnections);
//config.setPoolName(poolName);
return new HikariDataSource(config);
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean factory =
new LocalContainerEntityManagerFactoryBean();
factory.setDataSource(dataSource());
factory.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
factory.setPackagesToScan("com.target.storetaskcount.entity");
factory.setJpaProperties(additionalProps());
return factory;
}
@Configuration
public class PostgresDataSource {
@Bean
@ConfigurationProperties("app.datasource")
public HikariDataSource hikariDataSource() {
return DataSourceBuilder
.create()
.type(HikariDataSource.class)
.build();
}
}
@Primary
@Bean(name = "ProdDatasource")
public DataSource datasource() {
HikariDataSource dataSource = new HikariDataSource();
dataSource.setDriverClassName("org.postgresql.Driver");
// dataSource.setJdbcUrl("jdbc:postgresql://localhost:5432/places");
dataSource.setUsername("sddsdf");
dataSource.setPassword("xxx");
dataSource.setMaximumPoolSize(40);
dataSource.setMinimumIdle(5);
return dataSource;
}
constructor - HikariConfigvoid initDatabaseConnectionPool() { HikariConfig hikariConfig = new HikariConfig("/database.properties"); dataSource = new HikariDataSource(hikariConfig); }
jdbcUrl=jdbc:mariadb://localhost:3306/jdbc_demo dataSource.username=user dataSource.password=password
HikariConfig config = new HikariConfig(); config.setJdbcUrl(...); config.setMaximumPoolSize(...); config.setMinimumIdle(...); HikariDataSource dataSource= new HikariDataSource(config);
HikariDataSource dataSource; void initDatabaseConnectionPool() { dataSource = new HikariDataSource(); dataSource.setJdbcUrl("jdbcUrl=jdbc:mariadb://localhost:3306/jdbc_demo"); dataSource.setUsername("user"); dataSource.setPassword("pasword"); } void closeDatabaseConnectionPool() { dataSource.close(); } void insertData(String name, int rating) throws SQLException { try (Connection connection = dataSource.getConnection()) { ... } }
try (Connection conn = dataSource.getConnection();) { // execute some query... }getConnection metodu - String username + String password
spring:
profiles: dev
datasource:
hikari:
minimum-idle: 1
maximum-pool-size: 5
pool-name: yourPoolName
auto-commit: false
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://xxx
username: xx
password: xx
maximumPoolSize: 5
type: com.zaxxer.hikari.HikariDataSource
setPoolName metoduspring:
application:
name: miq-batch
datasource:
url: jdbc:mysql://localhost:3306/scdf
username: root
password: root
driverClassName: org.mariadb.jdbc.Driver
testOnBorrow: true
validationQuery: SELECT 1
hikari:
pool-name: SpringBootHikariCP