|
@@ -1,13 +1,15 @@
|
|
|
package com.gxzc.zen.orm
|
|
|
|
|
|
import com.alibaba.druid.pool.DruidDataSource
|
|
|
-import com.gxzc.zen.orm.base.BaseDataSourceProperties
|
|
|
+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.SqlSessionFactoryBean
|
|
|
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
|
|
@@ -17,12 +19,12 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager
|
|
|
import javax.sql.DataSource
|
|
|
|
|
|
/**
|
|
|
- * Sys 数据源配置<br>
|
|
|
- * 扫描路径为 com.gxzc.zen.*.sys
|
|
|
+ * Rec 数据源配置<br>
|
|
|
+ * 扫描路径为 com.gxzc.zen.*.rec
|
|
|
* @author NorthLan at 2018/1/26
|
|
|
*/
|
|
|
@Configuration
|
|
|
-@MapperScan(basePackages = ["com.gxzc.zen.api.rec.mapper"])
|
|
|
+@MapperScan(basePackages = ["com.gxzc.zen.api.rec.mapper"], sqlSessionTemplateRef = RecDataSourceConfig.SQL_SESSION_TEMPLATE_NAME)
|
|
|
class RecDataSourceConfig {
|
|
|
companion object {
|
|
|
const val DATASOURCE_NAME: String = "recDataSource"
|
|
@@ -32,15 +34,14 @@ class RecDataSourceConfig {
|
|
|
val logger: Logger = LoggerFactory.getLogger(RecDataSourceConfig::class.java)
|
|
|
}
|
|
|
|
|
|
- @Bean(name = ["recDataSourceProperties"])
|
|
|
- @ConfigurationProperties(prefix = "druid.datasource.rec")
|
|
|
- fun properties(): BaseDataSourceProperties {
|
|
|
- return BaseDataSourceProperties()
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private lateinit var properties: MybatisPlusProperties
|
|
|
+
|
|
|
+ private val mapperLocation: String = "classpath:/mapping/rec/*.xml"
|
|
|
|
|
|
@Bean(DATASOURCE_NAME)
|
|
|
@ConfigurationProperties(prefix = "druid.datasource.rec")
|
|
|
- fun dataSource(@Qualifier("recDataSourceProperties") properties: BaseDataSourceProperties): DataSource {
|
|
|
+ fun dataSource(): DataSource {
|
|
|
return DruidDataSource()
|
|
|
}
|
|
|
|
|
@@ -49,18 +50,20 @@ class RecDataSourceConfig {
|
|
|
return DataSourceTransactionManager(dataSource)
|
|
|
}
|
|
|
|
|
|
-// @Bean(SQL_SESSION_FACTORY_NAME)
|
|
|
-// fun sqlSessionFactory(@Qualifier(DATASOURCE_NAME) dataSource: DataSource, @Qualifier("recDataSourceProperties") properties: BaseDataSourceProperties): SqlSessionFactory {
|
|
|
-// return SqlSessionFactoryBean().let {
|
|
|
-// it.setDataSource(dataSource)
|
|
|
-// it.setMapperLocations(PathMatchingResourcePatternResolver().getResources(properties.mapperLocation))
|
|
|
-// it.`object`
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Bean(SQL_SESSION_TEMPLATE_NAME)
|
|
|
-//// @Order(-1)
|
|
|
-// fun sqlSessionTemplate(@Qualifier(SQL_SESSION_FACTORY_NAME) sqlSessionFactory: SqlSessionFactory): SqlSessionTemplate {
|
|
|
-// return SqlSessionTemplate(sqlSessionFactory)
|
|
|
-// }
|
|
|
+ @Bean(SQL_SESSION_FACTORY_NAME)
|
|
|
+ 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)
|
|
|
+ fun sqlSessionTemplate(@Qualifier(SQL_SESSION_FACTORY_NAME) sqlSessionFactory: SqlSessionFactory): SqlSessionTemplate {
|
|
|
+ return SqlSessionTemplate(sqlSessionFactory)
|
|
|
+ }
|
|
|
}
|