|
@@ -1,14 +1,14 @@
|
|
package com.gxzc.zen.orm.config
|
|
package com.gxzc.zen.orm.config
|
|
|
|
|
|
import com.alibaba.druid.pool.xa.DruidXADataSource
|
|
import com.alibaba.druid.pool.xa.DruidXADataSource
|
|
-import com.atomikos.icatch.jta.UserTransactionImp
|
|
|
|
-import com.atomikos.icatch.jta.UserTransactionManager
|
|
|
|
import com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean
|
|
import com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean
|
|
import com.baomidou.mybatisplus.spring.boot.starter.MybatisPlusProperties
|
|
import com.baomidou.mybatisplus.spring.boot.starter.MybatisPlusProperties
|
|
import com.baomidou.mybatisplus.spring.boot.starter.SpringBootVFS
|
|
import com.baomidou.mybatisplus.spring.boot.starter.SpringBootVFS
|
|
import com.gxzc.zen.orm.DynamicMultipleDataSource
|
|
import com.gxzc.zen.orm.DynamicMultipleDataSource
|
|
import com.gxzc.zen.orm.contants.DSKey
|
|
import com.gxzc.zen.orm.contants.DSKey
|
|
|
|
+import org.apache.ibatis.plugin.Interceptor
|
|
import org.slf4j.LoggerFactory
|
|
import org.slf4j.LoggerFactory
|
|
|
|
+import org.springframework.beans.factory.ObjectProvider
|
|
import org.springframework.beans.factory.annotation.Autowired
|
|
import org.springframework.beans.factory.annotation.Autowired
|
|
import org.springframework.beans.factory.annotation.Qualifier
|
|
import org.springframework.beans.factory.annotation.Qualifier
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
|
@@ -19,8 +19,6 @@ import org.springframework.context.annotation.Bean
|
|
import org.springframework.context.annotation.Configuration
|
|
import org.springframework.context.annotation.Configuration
|
|
import org.springframework.context.annotation.DependsOn
|
|
import org.springframework.context.annotation.DependsOn
|
|
import org.springframework.context.annotation.Primary
|
|
import org.springframework.context.annotation.Primary
|
|
-import org.springframework.transaction.PlatformTransactionManager
|
|
|
|
-import org.springframework.transaction.jta.JtaTransactionManager
|
|
|
|
import javax.sql.DataSource
|
|
import javax.sql.DataSource
|
|
import javax.sql.XADataSource
|
|
import javax.sql.XADataSource
|
|
|
|
|
|
@@ -30,20 +28,16 @@ import javax.sql.XADataSource
|
|
* @author NorthLan at 2018/1/29
|
|
* @author NorthLan at 2018/1/29
|
|
*/
|
|
*/
|
|
@Configuration
|
|
@Configuration
|
|
-@EnableConfigurationProperties(MybatisPlusProperties::class)
|
|
|
|
-@ConditionalOnProperty(prefix = "orm", name = ["multi-datasource-enable"], havingValue = "true", matchIfMissing = true)
|
|
|
|
|
|
+// @ConditionalOnProperty(prefix = "orm", name = ["multi-datasource-enable"], havingValue = "true", matchIfMissing = true)
|
|
class MultipleDataSourceConfig {
|
|
class MultipleDataSourceConfig {
|
|
companion object {
|
|
companion object {
|
|
private val logger = LoggerFactory.getLogger(MultipleDataSourceConfig::class.java)
|
|
private val logger = LoggerFactory.getLogger(MultipleDataSourceConfig::class.java)
|
|
}
|
|
}
|
|
|
|
|
|
- init{
|
|
|
|
|
|
+ init {
|
|
logger.info("MultipleDataSourceConfig initializing...")
|
|
logger.info("MultipleDataSourceConfig initializing...")
|
|
}
|
|
}
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private lateinit var properties: MybatisPlusProperties
|
|
|
|
-
|
|
|
|
@Bean(DSKey.DSKEY_SYS + "druid")
|
|
@Bean(DSKey.DSKEY_SYS + "druid")
|
|
@ConfigurationProperties(prefix = "datasource.sys")
|
|
@ConfigurationProperties(prefix = "datasource.sys")
|
|
fun dataSourceSysDruid(): XADataSource {
|
|
fun dataSourceSysDruid(): XADataSource {
|
|
@@ -76,48 +70,11 @@ class MultipleDataSourceConfig {
|
|
@Bean
|
|
@Bean
|
|
fun multipleDataSource(@Qualifier(DSKey.DSKEY_SYS) dataSourceSys: DataSource,
|
|
fun multipleDataSource(@Qualifier(DSKey.DSKEY_SYS) dataSourceSys: DataSource,
|
|
@Qualifier(DSKey.DSKEY_BUSINESS) dataSourceBus: DataSource): DynamicMultipleDataSource {
|
|
@Qualifier(DSKey.DSKEY_BUSINESS) dataSourceBus: DataSource): DynamicMultipleDataSource {
|
|
- return DynamicMultipleDataSource().also {
|
|
|
|
- it.setTargetDataSources(mapOf(
|
|
|
|
- Pair(DSKey.DSKEY_SYS, dataSourceSys),
|
|
|
|
- Pair(DSKey.DSKEY_BUSINESS, dataSourceBus)))
|
|
|
|
- it.setDefaultTargetDataSource(dataSourceSys)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-// @Bean("tx1")
|
|
|
|
-// fun platformTransactionManager(): PlatformTransactionManager {
|
|
|
|
-// return JtaTransactionManager().also {
|
|
|
|
-// it.userTransaction = UserTransactionImp()
|
|
|
|
-// it.transactionManager = UserTransactionManager()
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// @Bean
|
|
|
|
-// fun transactionManager(dynamicMultipleDataSource: DynamicMultipleDataSource): DataSourceTransactionManager {
|
|
|
|
-// return DataSourceTransactionManager(dynamicMultipleDataSource)
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
- @Bean
|
|
|
|
- @Primary
|
|
|
|
- fun mybatisSqlSessionFactoryBean(dynamicMultipleDataSource: DynamicMultipleDataSource): MybatisSqlSessionFactoryBean {
|
|
|
|
- return MybatisSqlSessionFactoryBean().also {
|
|
|
|
- it.setDataSource(dynamicMultipleDataSource)
|
|
|
|
- it.vfs = SpringBootVFS::class.java
|
|
|
|
- it.setConfiguration(properties.configuration)
|
|
|
|
- it.setGlobalConfig(properties.globalConfig?.convertGlobalConfiguration())
|
|
|
|
- it.setMapperLocations(properties.resolveMapperLocations())
|
|
|
|
|
|
+ return DynamicMultipleDataSource().apply {
|
|
|
|
+ setTargetDataSources(mapOf(
|
|
|
|
+ DSKey.DSKEY_SYS to dataSourceSys,
|
|
|
|
+ DSKey.DSKEY_BUSINESS to dataSourceBus))
|
|
|
|
+ setDefaultTargetDataSource(dataSourceSys)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-// override fun annotationDrivenTransactionManager(): PlatformTransactionManager {
|
|
|
|
-// return transactionManager()
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// @Bean
|
|
|
|
-// fun sqlSessionFactory(dynamicMultipleDataSource: DynamicMultipleDataSource): SqlSessionFactory {
|
|
|
|
-// return SqlSessionFactoryBean().let {
|
|
|
|
-// it.setDataSource(dynamicMultipleDataSource)
|
|
|
|
-// it.`object`
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
}
|
|
}
|