|
@@ -1,74 +1,68 @@
|
|
|
-package com.gxzc.zen.orm
|
|
|
-
|
|
|
-import com.alibaba.druid.pool.DruidDataSource
|
|
|
-import com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean
|
|
|
-import com.baomidou.mybatisplus.spring.boot.starter.MybatisPlusProperties
|
|
|
-import com.baomidou.mybatisplus.spring.boot.starter.SpringBootVFS
|
|
|
-import org.apache.ibatis.session.SqlSessionFactory
|
|
|
-import org.mybatis.spring.SqlSessionTemplate
|
|
|
-import org.mybatis.spring.annotation.MapperScan
|
|
|
-import org.slf4j.Logger
|
|
|
-import org.slf4j.LoggerFactory
|
|
|
-import org.springframework.beans.factory.annotation.Autowired
|
|
|
-import org.springframework.beans.factory.annotation.Qualifier
|
|
|
-import org.springframework.boot.context.properties.ConfigurationProperties
|
|
|
-import org.springframework.context.annotation.Bean
|
|
|
-import org.springframework.context.annotation.Configuration
|
|
|
-import org.springframework.context.annotation.Primary
|
|
|
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver
|
|
|
-import org.springframework.jdbc.datasource.DataSourceTransactionManager
|
|
|
-import javax.sql.DataSource
|
|
|
-
|
|
|
-/**
|
|
|
- * Sys 数据源配置<br>
|
|
|
- * 扫描路径为 com.gxzc.zen.*.sys
|
|
|
- * @author NorthLan at 2018/1/26
|
|
|
- */
|
|
|
-@Configuration
|
|
|
-@MapperScan(basePackages = ["com.gxzc.zen.api.sys.mapper"], sqlSessionTemplateRef = SysDataSourceConfig.SQL_SESSION_TEMPLATE_NAME)
|
|
|
-class SysDataSourceConfig {
|
|
|
- companion object {
|
|
|
- const val DATASOURCE_NAME: String = "sysDataSource"
|
|
|
- const val TRANSACTION_MANAGER_NAME: String = "sysTransactionManager"
|
|
|
- const val SQL_SESSION_FACTORY_NAME: String = "sysSqlSessionFactory"
|
|
|
- const val SQL_SESSION_TEMPLATE_NAME: String = "sysSqlSessionTemplate"
|
|
|
- val logger: Logger = LoggerFactory.getLogger(SysDataSourceConfig::class.java)
|
|
|
- }
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private lateinit var properties: MybatisPlusProperties
|
|
|
-
|
|
|
- private val mapperLocation: String = "classpath:/mapping/sys/*.xml"
|
|
|
-
|
|
|
- @Bean(DATASOURCE_NAME)
|
|
|
- @ConfigurationProperties(prefix = "druid.datasource.sys")
|
|
|
- @Primary
|
|
|
- fun dataSource(): DataSource {
|
|
|
- return DruidDataSource()
|
|
|
- }
|
|
|
-
|
|
|
- @Bean(TRANSACTION_MANAGER_NAME)
|
|
|
- @Primary
|
|
|
- fun transactionManager(@Qualifier(DATASOURCE_NAME) dataSource: DataSource): DataSourceTransactionManager {
|
|
|
- return DataSourceTransactionManager(dataSource)
|
|
|
- }
|
|
|
-
|
|
|
- @Bean(SQL_SESSION_FACTORY_NAME)
|
|
|
- @Primary
|
|
|
- fun sqlSessionFactory(@Qualifier(DATASOURCE_NAME) dataSource: DataSource): SqlSessionFactory {
|
|
|
- return MybatisSqlSessionFactoryBean().let {
|
|
|
- it.setDataSource(dataSource)
|
|
|
- it.vfs = SpringBootVFS::class.java
|
|
|
- it.setConfiguration(properties.configuration)
|
|
|
- it.setGlobalConfig(properties.globalConfig.convertGlobalConfiguration())
|
|
|
- it.setMapperLocations(PathMatchingResourcePatternResolver().getResources(mapperLocation))
|
|
|
- it.`object`
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Bean(SQL_SESSION_TEMPLATE_NAME)
|
|
|
- @Primary
|
|
|
- fun sqlSessionTemplate(@Qualifier(SQL_SESSION_FACTORY_NAME) sqlSessionFactory: SqlSessionFactory): SqlSessionTemplate {
|
|
|
- return SqlSessionTemplate(sqlSessionFactory)
|
|
|
- }
|
|
|
-}
|
|
|
+//package com.gxzc.zen.orm
|
|
|
+//
|
|
|
+//import com.alibaba.druid.pool.DruidDataSource
|
|
|
+//import com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean
|
|
|
+//import com.baomidou.mybatisplus.spring.boot.starter.MybatisPlusProperties
|
|
|
+//import com.baomidou.mybatisplus.spring.boot.starter.SpringBootVFS
|
|
|
+//import org.apache.ibatis.session.SqlSessionFactory
|
|
|
+//import org.mybatis.spring.annotation.MapperScan
|
|
|
+//import org.slf4j.Logger
|
|
|
+//import org.slf4j.LoggerFactory
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired
|
|
|
+//import org.springframework.beans.factory.annotation.Qualifier
|
|
|
+//import org.springframework.boot.context.properties.ConfigurationProperties
|
|
|
+//import org.springframework.boot.context.properties.EnableConfigurationProperties
|
|
|
+//import org.springframework.context.annotation.Bean
|
|
|
+//import org.springframework.context.annotation.Configuration
|
|
|
+//import org.springframework.context.annotation.Primary
|
|
|
+//import org.springframework.core.io.support.PathMatchingResourcePatternResolver
|
|
|
+//import org.springframework.jdbc.datasource.DataSourceTransactionManager
|
|
|
+//import javax.sql.DataSource
|
|
|
+//
|
|
|
+///**
|
|
|
+// * Sys 数据源配置<br>
|
|
|
+// * 扫描路径为 com.gxzc.zen.*.sys
|
|
|
+// * @author NorthLan at 2018/1/26
|
|
|
+// */
|
|
|
+//@Configuration
|
|
|
+//@EnableConfigurationProperties(MybatisPlusProperties::class)
|
|
|
+//@MapperScan(basePackages = ["com.gxzc.zen.api.sys.mapper"], sqlSessionFactoryRef = SysDataSourceConfig.SQL_SESSION_FACTORY_NAME)
|
|
|
+//class SysDataSourceConfig {
|
|
|
+// companion object {
|
|
|
+// const val DATASOURCE_NAME: String = "sysDataSource"
|
|
|
+// const val TRANSACTION_MANAGER_NAME: String = "sysTransactionManager"
|
|
|
+// const val SQL_SESSION_FACTORY_NAME: String = "sysSqlSessionFactory"
|
|
|
+// val logger: Logger = LoggerFactory.getLogger(SysDataSourceConfig::class.java)
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private lateinit var properties: MybatisPlusProperties
|
|
|
+//
|
|
|
+// private val mapperLocation: String = "classpath:/mapping/sys/*.xml"
|
|
|
+//
|
|
|
+//// @Bean(DATASOURCE_NAME)
|
|
|
+//// @ConfigurationProperties(prefix = "datasource.sys")
|
|
|
+//// @Primary
|
|
|
+//// fun dataSource(): DataSource {
|
|
|
+//// return DruidDataSource()
|
|
|
+//// }
|
|
|
+//
|
|
|
+// @Bean(TRANSACTION_MANAGER_NAME)
|
|
|
+// @Primary
|
|
|
+// fun transactionManager(@Qualifier(DATASOURCE_NAME) dataSource: DataSource): DataSourceTransactionManager {
|
|
|
+// return DataSourceTransactionManager(dataSource)
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Bean(SQL_SESSION_FACTORY_NAME)
|
|
|
+// @Primary
|
|
|
+// fun sqlSessionFactory(@Qualifier(DATASOURCE_NAME) dataSource: DataSource): SqlSessionFactory {
|
|
|
+// return MybatisSqlSessionFactoryBean().let {
|
|
|
+// it.setDataSource(dataSource)
|
|
|
+// it.vfs = SpringBootVFS::class.java
|
|
|
+// it.setConfiguration(properties.configuration)
|
|
|
+// it.setGlobalConfig(properties.globalConfig?.convertGlobalConfiguration())
|
|
|
+// it.setMapperLocations(PathMatchingResourcePatternResolver().getResources(mapperLocation))
|
|
|
+// it.`object`
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|