|
@@ -3,34 +3,22 @@ package com.gxzc.zen.config
|
|
|
import com.alibaba.druid.pool.DruidDataSource
|
|
|
import com.alibaba.druid.support.http.StatViewServlet
|
|
|
import com.alibaba.druid.support.http.WebStatFilter
|
|
|
-import com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean
|
|
|
-import com.baomidou.mybatisplus.spring.boot.starter.SpringBootVFS
|
|
|
import org.mybatis.spring.annotation.MapperScan
|
|
|
import org.slf4j.LoggerFactory
|
|
|
-import org.springframework.beans.factory.annotation.Autowired
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
|
|
import org.springframework.boot.web.servlet.FilterRegistrationBean
|
|
|
import org.springframework.boot.web.servlet.ServletRegistrationBean
|
|
|
import org.springframework.context.annotation.Bean
|
|
|
import org.springframework.context.annotation.Configuration
|
|
|
-import org.springframework.core.annotation.Order
|
|
|
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver
|
|
|
import java.sql.SQLException
|
|
|
import javax.sql.DataSource
|
|
|
|
|
|
|
|
|
-//@Order(1)
|
|
|
@Configuration
|
|
|
@ConfigurationProperties(prefix = "druid.datasource-sys")
|
|
|
@MapperScan(basePackages = ["com.gxzc.zen.sys"])
|
|
|
class SysDruidConfig:DruidConfig()
|
|
|
|
|
|
-//@Order(2)
|
|
|
-//@Configuration
|
|
|
-//@ConfigurationProperties(prefix = "mybatis-plus")
|
|
|
-//@MapperScan(basePackages = ["com.gxzc.zen"])
|
|
|
-//class SysMyBatisPlusConfig:MyBatisPlusConfig<SysDruidConfig>()
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
@@ -92,42 +80,6 @@ open class DruidConfig {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-open class MyBatisPlusConfig<T:DruidConfig>{
|
|
|
- var mapperLocations:String?=null
|
|
|
- var typeAliasesPackage:String?=null
|
|
|
- var globalConfigs:Map<String,Any>?=null
|
|
|
- var configurations:Map<String,Any>?=null
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private val datasource:T?=null
|
|
|
- private val resolver=PathMatchingResourcePatternResolver()
|
|
|
- private var sqlSessionFactory:MybatisSqlSessionFactoryBean?=null
|
|
|
-
|
|
|
- /**
|
|
|
- * 这里全部使用mybatis-autoconfigure 已经自动加载的资源。不手动指定
|
|
|
- * 配置文件和mybatis-boot的配置文件同步
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Bean
|
|
|
- open fun mybatisSqlSessionFactoryBean(): MybatisSqlSessionFactoryBean {
|
|
|
- sqlSessionFactory = MybatisSqlSessionFactoryBean()
|
|
|
- sqlSessionFactory?.setDataSource(datasource?.getDatasource())
|
|
|
- sqlSessionFactory?.vfs = SpringBootVFS::class.java
|
|
|
- sqlSessionFactory?.setTypeAliasesPackage(typeAliasesPackage)
|
|
|
- val resources = resolver.getResources(mapperLocations)
|
|
|
- sqlSessionFactory?.setMapperLocations(resources)
|
|
|
-
|
|
|
- val conftion= org.apache.ibatis.session.Configuration()
|
|
|
- conftion.isMapUnderscoreToCamelCase=configurations?.get("map-underscore-to-camel-case") as Boolean
|
|
|
- conftion.isCacheEnabled=configurations?.get("cache-enabled") as Boolean
|
|
|
- conftion.isLazyLoadingEnabled=configurations?.get("lazyLoadingEnabled") as Boolean
|
|
|
- conftion.isMultipleResultSetsEnabled=configurations?.get("multipleResultSetsEnabled") as Boolean
|
|
|
-
|
|
|
- sqlSessionFactory?.setConfiguration(conftion)
|
|
|
- return sqlSessionFactory!!
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
|
|
|
|