Search in sources :

Example 11 with MybatisConfiguration

use of com.baomidou.mybatisplus.core.MybatisConfiguration in project zhili-dataplatform by javasqlbug.

the class SpringConnectionFactory method sqlSessionFactory.

/**
 * * get sql session factory
 *
 * @return sqlSessionFactory
 * @throws Exception sqlSessionFactory exception
 */
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
    MybatisConfiguration configuration = new MybatisConfiguration();
    configuration.setMapUnderscoreToCamelCase(true);
    configuration.setCacheEnabled(false);
    configuration.setCallSettersOnNulls(true);
    configuration.setJdbcTypeForNull(JdbcType.NULL);
    configuration.addInterceptor(paginationInterceptor());
    MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
    sqlSessionFactoryBean.setConfiguration(configuration);
    sqlSessionFactoryBean.setDataSource(dataSource());
    GlobalConfig.DbConfig dbConfig = new GlobalConfig.DbConfig();
    dbConfig.setIdType(IdType.AUTO);
    GlobalConfig globalConfig = new GlobalConfig();
    globalConfig.setDbConfig(dbConfig);
    sqlSessionFactoryBean.setGlobalConfig(globalConfig);
    sqlSessionFactoryBean.setTypeAliasesPackage("com.niezhili.dataplatform.metadata.dao.entity");
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("com/niezhili/dataplatform/metadata/dao/mapper/*Mapper.xml"));
    sqlSessionFactoryBean.setTypeEnumsPackage("com.niezhili.dataplatform.metadata.dao.*.enums");
    sqlSessionFactoryBean.setDatabaseIdProvider(databaseIdProvider());
    return sqlSessionFactoryBean.getObject();
}
Also used : MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration) GlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 12 with MybatisConfiguration

use of com.baomidou.mybatisplus.core.MybatisConfiguration in project zhili-dataplatform by javasqlbug.

the class SpringConnectionFactory method sqlSessionFactory.

/**
 * * get sql session factory
 *
 * @return sqlSessionFactory
 * @throws Exception sqlSessionFactory exception
 */
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
    MybatisConfiguration configuration = new MybatisConfiguration();
    configuration.setMapUnderscoreToCamelCase(true);
    configuration.setCacheEnabled(false);
    configuration.setCallSettersOnNulls(true);
    configuration.setJdbcTypeForNull(JdbcType.NULL);
    configuration.addInterceptor(paginationInterceptor());
    MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
    sqlSessionFactoryBean.setConfiguration(configuration);
    sqlSessionFactoryBean.setDataSource(dataSource());
    GlobalConfig.DbConfig dbConfig = new GlobalConfig.DbConfig();
    dbConfig.setIdType(IdType.AUTO);
    GlobalConfig globalConfig = new GlobalConfig();
    globalConfig.setDbConfig(dbConfig);
    sqlSessionFactoryBean.setGlobalConfig(globalConfig);
    sqlSessionFactoryBean.setTypeAliasesPackage("com.niezhili.dataplatform.dataservice.dao.entity");
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("com/niezhili/dataplatform/dataservice/dao/mapper/*Mapper.xml"));
    sqlSessionFactoryBean.setTypeEnumsPackage("com.niezhili.dataplatform.dataservice.dao.*.enums");
    sqlSessionFactoryBean.setDatabaseIdProvider(databaseIdProvider());
    return sqlSessionFactoryBean.getObject();
}
Also used : MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration) GlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 13 with MybatisConfiguration

use of com.baomidou.mybatisplus.core.MybatisConfiguration in project solon by noear.

the class MybatisAdapterPlus method initConfiguration.

/**
 * 初始化配置
 */
@Override
protected void initConfiguration(Environment environment) {
    // for configuration section
    config = new MybatisConfiguration(environment);
    Props cfgProps = dsProps.getProp("configuration");
    if (cfgProps.size() > 0) {
        Utils.injectProperties(config, cfgProps);
    }
    // for globalConfig section
    globalConfig = new GlobalConfig().setDbConfig(new GlobalConfig.DbConfig());
    Props globalProps = dsProps.getProp("globalConfig");
    if (globalProps.size() > 0) {
        // 尝试配置注入
        Utils.injectProperties(globalConfig, globalProps);
    }
    GlobalConfigUtils.setGlobalConfig(config, globalConfig);
}
Also used : MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration) GlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig)

Example 14 with MybatisConfiguration

use of com.baomidou.mybatisplus.core.MybatisConfiguration in project springboot-templet-start by thedestiny.

the class MybatisPlusConfigSecondDatasource method secSqlSessionFactory.

// sec
@Bean("secSqlSessionFactory")
public SqlSessionFactory secSqlSessionFactory(@Qualifier("secDatasource") DataSource dataSource) throws Exception {
    MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
    sqlSessionFactory.setDataSource(dataSource);
    MybatisConfiguration configuration = new MybatisConfiguration();
    configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
    configuration.setJdbcTypeForNull(JdbcType.NULL);
    configuration.setMapUnderscoreToCamelCase(true);
    configuration.setCacheEnabled(false);
    sqlSessionFactory.setConfiguration(configuration);
    sqlSessionFactory.setTypeAliasesPackage("com.destiny.hiootamus.entity.second");
    sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/second/*.xml"));
    sqlSessionFactory.setPlugins(plusInterceptor);
    sqlSessionFactory.setGlobalConfig(new GlobalConfig().setBanner(false));
    return sqlSessionFactory.getObject();
}
Also used : MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration) GlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 15 with MybatisConfiguration

use of com.baomidou.mybatisplus.core.MybatisConfiguration in project scaleph by flowerfine.

the class LogDataSourceConfig method logSqlSessionFactory.

@Bean(LOG_SQL_SESSION_FACTORY)
public SqlSessionFactory logSqlSessionFactory() throws Exception {
    MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
    MybatisPlusProperties props = new MybatisPlusProperties();
    props.setMapperLocations(new String[] { LOG_MAPPER_XML_PATH });
    factoryBean.setMapperLocations(props.resolveMapperLocations());
    MybatisConfiguration configuration = new MybatisConfiguration();
    configuration.setMapUnderscoreToCamelCase(true);
    configuration.setLogImpl(Slf4jImpl.class);
    factoryBean.setConfiguration(configuration);
    factoryBean.setDataSource(logDataSource());
    factoryBean.setTypeAliasesPackage(LOG_ENTITY_PACKAGE);
    factoryBean.setPlugins(mybatisPlusInterceptor);
    return factoryBean.getObject();
}
Also used : MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration) MybatisPlusProperties(com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

MybatisConfiguration (com.baomidou.mybatisplus.core.MybatisConfiguration)17 MybatisSqlSessionFactoryBean (com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean)12 Bean (org.springframework.context.annotation.Bean)10 GlobalConfig (com.baomidou.mybatisplus.core.config.GlobalConfig)9 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)7 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)4 ConfigurationCustomizer (com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer)3 MybatisPlusProperties (com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties)2 MybatisPlusInterceptor (com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor)2 PaginationInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor)2 Environment (org.apache.ibatis.mapping.Environment)2 TransactionFactory (org.apache.ibatis.transaction.TransactionFactory)2 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)2 MybatisSqlSessionFactoryBuilder (com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder)1 MybatisMapWrapperFactory (com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory)1 PaginationInterceptor (com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor)1 OptimisticLockerInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor)1 DataSource (javax.sql.DataSource)1 Primary (org.springframework.context.annotation.Primary)1 Resource (org.springframework.core.io.Resource)1