Browse Source
# Conflicts: # yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.javazyh
小久哥
3 years ago
13 changed files with 145 additions and 71 deletions
@ -0,0 +1,69 @@ |
|||||||
|
package cn.iocoder.yudao.framework.quartz.config; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.ObjectProvider; |
||||||
|
import org.springframework.beans.factory.annotation.Qualifier; |
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter; |
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; |
||||||
|
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; |
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
||||||
|
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; |
||||||
|
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; |
||||||
|
import org.springframework.boot.autoconfigure.quartz.*; |
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
||||||
|
import org.springframework.boot.sql.init.dependency.DatabaseInitializationDependencyConfigurer; |
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
import org.springframework.context.annotation.Import; |
||||||
|
import org.springframework.core.annotation.Order; |
||||||
|
import org.springframework.core.io.ResourceLoader; |
||||||
|
import org.springframework.transaction.PlatformTransactionManager; |
||||||
|
import org.springframework.transaction.TransactionManager; |
||||||
|
|
||||||
|
import javax.sql.DataSource; |
||||||
|
@Configuration |
||||||
|
@ConditionalOnProperty(prefix = "spring.quartz", name = "job-store-type", havingValue = "jdbc") |
||||||
|
@Import(DatabaseInitializationDependencyConfigurer.class) |
||||||
|
@EnableConfigurationProperties(QuartzProperties.class) |
||||||
|
@AutoConfigureAfter({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, |
||||||
|
LiquibaseAutoConfiguration.class, FlywayAutoConfiguration.class }) |
||||||
|
public class JdbcStoreTypeConfiguration { |
||||||
|
|
||||||
|
|
||||||
|
@Bean |
||||||
|
@Order(0) |
||||||
|
public SchedulerFactoryBeanCustomizer dataSourceCustomizer(QuartzProperties properties, |
||||||
|
DataSource dataSource, |
||||||
|
@QuartzDataSource ObjectProvider<DataSource> quartzDataSource, |
||||||
|
TransactionManager transactionManager |
||||||
|
) { |
||||||
|
return (schedulerFactoryBean) -> { |
||||||
|
DataSource dataSourceToUse = getDataSource(dataSource, quartzDataSource); |
||||||
|
schedulerFactoryBean.setDataSource(dataSourceToUse); |
||||||
|
schedulerFactoryBean.setTransactionManager((PlatformTransactionManager) transactionManager); |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
private DataSource getDataSource(DataSource dataSource, ObjectProvider<DataSource> quartzDataSource) { |
||||||
|
DataSource dataSourceIfAvailable = quartzDataSource.getIfAvailable(); |
||||||
|
return (dataSourceIfAvailable != null) ? dataSourceIfAvailable : dataSource; |
||||||
|
} |
||||||
|
|
||||||
|
private PlatformTransactionManager getTransactionManager( |
||||||
|
ObjectProvider<PlatformTransactionManager> transactionManager, |
||||||
|
ObjectProvider<PlatformTransactionManager> quartzTransactionManager) { |
||||||
|
PlatformTransactionManager transactionManagerIfAvailable = quartzTransactionManager.getIfAvailable(); |
||||||
|
return (transactionManagerIfAvailable != null) ? transactionManagerIfAvailable |
||||||
|
: transactionManager.getIfUnique(); |
||||||
|
} |
||||||
|
|
||||||
|
@Bean |
||||||
|
@ConditionalOnMissingBean |
||||||
|
public QuartzDataSourceInitializer quartzDataSourceInitializer(DataSource dataSource, |
||||||
|
@QuartzDataSource ObjectProvider<DataSource> quartzDataSource, ResourceLoader resourceLoader, |
||||||
|
QuartzProperties properties) { |
||||||
|
DataSource dataSourceToUse = getDataSource(dataSource, quartzDataSource); |
||||||
|
return new QuartzDataSourceInitializer(dataSourceToUse, resourceLoader, properties); |
||||||
|
} |
||||||
|
} |
@ -1,3 +1,4 @@ |
|||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ |
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ |
||||||
cn.iocoder.yudao.framework.quartz.config.YudaoQuartzAutoConfiguration,\ |
cn.iocoder.yudao.framework.quartz.config.YudaoQuartzAutoConfiguration,\ |
||||||
cn.iocoder.yudao.framework.quartz.config.YudaoAsyncAutoConfiguration |
cn.iocoder.yudao.framework.quartz.config.YudaoAsyncAutoConfiguration,\ |
||||||
|
cn.iocoder.yudao.framework.quartz.config.JdbcStoreTypeConfiguration |
||||||
|
Loading…
Reference in new issue