This commit is contained in:
Fabio Formosa
2021-10-26 00:32:38 +02:00
parent e50a48bd4c
commit c4e8eb94d6
8 changed files with 230 additions and 226 deletions

View File

@@ -3,26 +3,30 @@ package it.fabioformosa.quartzmanager.persistence;
import it.fabioformosa.quartzmanager.common.properties.QuartzModuleProperties;
import liquibase.integration.spring.SpringLiquibase;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.*;
import javax.sql.DataSource;
@Configuration
@PropertySource("classpath:quartz-manager-application-persistence.properties")
@PropertySource("classpath:quartz-persistence.properties")
public class PersistenceConfig {
@Value("${quartz-manager.persistence.quartz.datasource.url}")
private String quartzDatasourceUrl;
@Value("${quartz-manager.persistence.quartz.datasource.user}")
private String quartzDatasourceUser;
@Value("${quartz-manager.persistence.quartz.datasource.password}")
private String quartzDatasourcePassword;
@Data
public class PersistenceDatasourceProps {
private String url;
private String changeLog;
private String contexts;
private String user;
private String password;
}
@Bean
@@ -42,19 +46,23 @@ public class PersistenceConfig {
}
@Bean("quartzPersistenceProperties")
@ConfigurationProperties(prefix = "spring.quartz")
public QuartzModuleProperties persistenceQuartzProps() {
return new QuartzModuleProperties();
public QuartzModuleProperties persistenceQuartzProps(QuartzPersistencePropConfig quartzPersistencePropConfig) {
QuartzModuleProperties quartzModuleProperties = new QuartzModuleProperties();
quartzModuleProperties.setProperties(quartzPersistencePropConfig.getProperties());
quartzModuleProperties.getProperties().setProperty("org.quartz.dataSource.quartzDataSource.URL", quartzDatasourceUrl);
quartzModuleProperties.getProperties().setProperty("org.quartz.dataSource.quartzDataSource.user", quartzDatasourceUser);
quartzModuleProperties.getProperties().setProperty("org.quartz.dataSource.quartzDataSource.password", quartzDatasourcePassword);
return quartzModuleProperties;
}
@Primary
@Bean
public DataSource quartzManagerDatasource(PersistenceDatasourceProps persistenceDatasourceProps) {
return DataSourceBuilder.create()
.url(persistenceDatasourceProps.getUrl())
.url(quartzDatasourceUrl)
.driverClassName("org.postgresql.Driver")
.username(persistenceDatasourceProps.getUser())
.password(persistenceDatasourceProps.getPassword())
.username(quartzDatasourceUser)
.password(quartzDatasourcePassword)
.build();
}

View File

@@ -0,0 +1,17 @@
package it.fabioformosa.quartzmanager.persistence;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import java.util.Properties;
@Configuration
@PropertySource("classpath:quartz-persistence.properties")
@ConfigurationProperties(prefix = "spring.quartz")
@Getter @Setter
public class QuartzPersistencePropConfig {
private Properties properties;
}

View File

@@ -1,20 +0,0 @@
spring.liquibase.url=jdbc:postgresql://localhost:5432/quartzmanager
spring.liquibase.change-log=classpath:db/quartz-scheduler/liquibase-changelog-master.xml
spring.liquibase.contexts=default
spring.liquibase.user=quartzmanager
spring.liquibase.password=quartzmanager
spring.quartz.job-store-type=jdbc
spring.quartz.initialize-schema=never
spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.driver=org.postgresql.Driver
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.URL=jdbc:postgresql://localhost:5432/quartzmanager
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.user=quartzmanager
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.password=quartzmanager
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.maxConnections=5
spring.quartz.properties.org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
spring.quartz.properties.org.quartz.jobStore.dataSource=quartzDataSource
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.provider=hikaricp
spring.quartz.properties.org.quartz.jobStore.misfireThreshold=1000
# org.quartz.jobStore.isClustered=true
# org.quartz.scheduler.instanceId=AUTO

View File

@@ -1,10 +1,13 @@
org.quartz.dataSource.quartzDataSource.driver = org.postgresql.Driver
org.quartz.dataSource.quartzDataSource.URL = jdbc:postgresql://localhost:5432/quartzmanager
org.quartz.dataSource.quartzDataSource.user quartzmanager
org.quartz.dataSource.quartzDataSource.password = quartzmanager
org.quartz.dataSource.quartzDataSource.maxConnections = 5
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.dataSource = quartzDataSource
org.quartz.dataSource.quartzDataSource.provider=hikaricp
org.quartz.jobStore.misfireThreshold=1000
spring.liquibase.change-log=classpath:db/quartz-scheduler/liquibase-changelog-master.xml
spring.liquibase.contexts=default
spring.quartz.job-store-type=jdbc
spring.quartz.initialize-schema=never
spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.driver=org.postgresql.Driver
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.maxConnections=5
spring.quartz.properties.org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
spring.quartz.properties.org.quartz.jobStore.dataSource=quartzDataSource
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.provider=hikaricp
spring.quartz.properties.org.quartz.jobStore.misfireThreshold=1000
# org.quartz.jobStore.isClustered=true
# org.quartz.scheduler.instanceId=AUTO