我最近从springbootstarter1.5.9.release(使用spring版本)更新了springboot/spring批处理应用程序 4.3.13.RELEASE
)=>2.2.4.release(使用spring版本 5.2.3.RELEASE
. 1.5.9.release正在使用 Hikari 2.6.3
; 我也尝试过这个版本在我的迁移/更新 2.2.4.RELEASE
我的应用程序版本。 2.2.4.RELEASE
使用 Hikari 3.4.2
两者似乎都不起作用。我正在使用 postgresql 42.2.9
这就是hikari在工作时(运行 1.5.9.RELEASE
我的应用程序的 Spring 启动版本):
3c22fb53ed64 2021-04-09 05:10:58.223 WARN CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - HikariPool-1 - maxLifetime is less than 30000ms, setting to default 1800000ms.
3c22fb53ed64 2021-04-09 05:10:58.223 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - HikariPool-1 - configuration:
3c22fb53ed64 2021-04-09 05:10:58.224 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - allowPoolSuspension.............false
3c22fb53ed64 2021-04-09 05:10:58.224 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - autoCommit......................false
3c22fb53ed64 2021-04-09 05:10:58.224 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - catalog.........................none
3c22fb53ed64 2021-04-09 05:10:58.224 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - connectionInitSql...............none
3c22fb53ed64 2021-04-09 05:10:58.224 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - connectionTestQuery.............none
3c22fb53ed64 2021-04-09 05:10:58.224 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - connectionTimeout...............60000
3c22fb53ed64 2021-04-09 05:10:58.224 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - dataSource......................none
3c22fb53ed64 2021-04-09 05:10:58.224 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - dataSourceClassName.............none
3c22fb53ed64 2021-04-09 05:10:58.224 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - dataSourceJNDI..................none
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - dataSourceProperties............{password=<masked>}
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - driverClassName.................none
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - healthCheckProperties...........{}
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - healthCheckRegistry.............none
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - idleTimeout.....................600000
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - initializationFailFast..........true
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - initializationFailTimeout.......1
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - isolateInternalQueries..........false
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - jdbc4ConnectionTest.............false
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - jdbcUrl........................."jdbc:postgresql://mydatabaseurl.mywebsite.com:5432/supercooldatabase"
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - leakDetectionThreshold..........0
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - maxLifetime.....................1800000
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - maximumPoolSize.................5
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - metricRegistry..................none
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - metricsTrackerFactory...........none
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - minimumIdle.....................5
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - password........................<masked>
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - poolName........................"HikariPool-1"
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - readOnly........................false
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - registerMbeans..................false
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - scheduledExecutor...............none
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - scheduledExecutorService........internal
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - threadFactory...................internal
3c22fb53ed64 2021-04-09 05:10:58.225 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - transactionIsolation............default
3c22fb53ed64 2021-04-09 05:10:58.226 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - username........................"mktgoffers_ddladmin"
3c22fb53ed64 2021-04-09 05:10:58.226 DEBUG CorrelationId=
[main] com.zaxxer.hikari.HikariConfig - validationTimeout...............5000
3c22fb53ed64 2021-04-09 05:10:58.226 INFO CorrelationId=
[main] com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
3c22fb53ed64 2021-04-09 05:10:59.377 DEBUG CorrelationId=
[main] com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection@14ed7ddf
3c22fb53ed64 2021-04-09 05:10:59.379 INFO CorrelationId=
[main] com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
3c22fb53ed64 2021-04-15 01:04:40.021 INFO CorrelationId=
[main] org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL82Dialect
您可以看到它用我的连接信息配置hikari,显示jdbc url,甚至添加postgresql连接。
这是它不工作时的样子,在我更新到spring boot之后 2.2.4.RELEASE
:
2021-04-15 01:14:11.681 INFO 75096 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-04-15 01:14:12.748 INFO 75096 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-04-15 01:14:12.760 INFO 75096 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL82Dialect
正如你所见,这是不同的。通常我不在乎日志,但当我的 JpaRepository
方法被称为 .saveAll()
,应用程序挂起/停止执行任何操作,并且从不写入数据库。在第一次之后,我感到困惑,并认为这是我在springbatch中设置的事务/实体管理器,但正如我之前所说的,我的所有代码/配置实际上都可以很好地工作(写入数据库) 1.5.9.RELEASE
Spring Boot。现在,我刚刚在日志中发现了这个数据库配置,我99%确定我的数据库连接甚至没有正确初始化。
这是我的应用程序yaml(这是一个代码段,但包含数据库连接的所有相关信息):
spring:
application:
name: My Super Cool App
profiles:
active: "myLocal,myLocalDev"
batch.job.enabled: false
datasource:
hikari:
maximumPoolSize: 5
connectionTimeout: 60000
max-lifetime: 20000
auto-commit: false
jpa:
database: POSTGRESQL
database-platform: org.hibernate.dialect.PostgreSQL82Dialect
show-sql: false
hibernate:
ddl-auto: none
properties:
hibernate:
jdbc.batch_size: 5000
order_inserts: true
flushMode: COMMIT
---
spring:
profiles: myLocal
datasource:
url: jdbc:postgresql://database-main-url.mywebsite.com:5432/cooldbname
username: mysuperkewluser
password: hahasupersecretpw
以及我的数据库配置定义databaseconfiguration.java:
@Configuration
@EnableTransactionManagement
public class DatabaseConfiguration {
@Autowired
private Environment envVar;
@Autowired
private KeyVault keyProvider;
@Bean(name = "dataSource")
@ConfigurationProperties(
prefix = "spring.datasource.hikari"
)
public DataSource dataSource(DataSourceProperties dataSourceProperties) {
log.debug("Configuring Datasource");
String dbPassword = keyProvider.getKeyProvider(dataSourceProperties.getPassword());
return DataSourceBuilder
.create(dataSourceProperties.getClassLoader())
.type(HikariDataSource.class)
.driverClassName(dataSourceProperties.getDriverClassName())
.url(dataSourceProperties.getUrl())
.username(dataSourceProperties.getUsername())
.password(dbPassword)
.build();
}
}
我在用这个 @Autowiring
我的spring批处理中的这个数据源 JobRepository
,这是在我的batchconfiguration.java类中定义的
@Configuration
@EnableBatchProcessing
public class BatchConfiguration {
// Autowiring of the JobBuilderFactory, StepBuilderFactory here
@Bean
public JobRepository jobRepository(PlatformTransactionManager transactionManager, @Qualifier("dataSource") DataSource dataSource) throws Exception {
JobRepositoryFactoryBean jobRepositoryFactoryBean = new JobRepositoryFactoryBean();
jobRepositoryFactoryBean.setDataSource(dataSource); // dataSource
jobRepositoryFactoryBean.setTransactionManager(transactionManager);
jobRepositoryFactoryBean.setDatabaseType("POSTGRES");
return jobRepositoryFactoryBean.getObject();
// more business logic code here
}
暂无答案!
目前还没有任何答案,快来回答吧!