Search in sources :

Example 21 with MybatisSqlSessionFactoryBean

use of com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean 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 22 with MybatisSqlSessionFactoryBean

use of com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean in project wakaka by Crysmart.

the class MyBatisConfig method sqlSessionFactoryBean.

@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactoryBean(DataSourceProxy dataSourceProxy) throws Exception {
    MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
    bean.setDataSource(dataSourceProxy);
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    // bean.setConfigLocation(resolver.getResource("classpath:mybatis-config.xml"));
    bean.setMapperLocations(resolver.getResources("classpath*:mybatis/**/*-mapper.xml"));
    SqlSessionFactory factory = null;
    try {
        factory = bean.getObject();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return factory;
}
Also used : MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 23 with MybatisSqlSessionFactoryBean

use of com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean in project wakaka by Crysmart.

the class MyBatisConfig method sqlSessionFactoryBean.

@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactoryBean(DataSourceProxy dataSourceProxy) throws Exception {
    MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
    bean.setDataSource(dataSourceProxy);
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    // bean.setConfigLocation(resolver.getResource("classpath:mybatis-config.xml"));
    bean.setMapperLocations(resolver.getResources("classpath*:mybatis/**/*-mapper.xml"));
    SqlSessionFactory factory = null;
    try {
        factory = bean.getObject();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return factory;
}
Also used : MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 24 with MybatisSqlSessionFactoryBean

use of com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean 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 25 with MybatisSqlSessionFactoryBean

use of com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean 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

MybatisSqlSessionFactoryBean (com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean)29 Bean (org.springframework.context.annotation.Bean)23 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)18 MybatisConfiguration (com.baomidou.mybatisplus.core.MybatisConfiguration)12 GlobalConfig (com.baomidou.mybatisplus.core.config.GlobalConfig)11 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)8 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)7 Resource (org.springframework.core.io.Resource)5 PaginationInterceptor (com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor)4 Interceptor (org.apache.ibatis.plugin.Interceptor)3 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)3 Primary (org.springframework.context.annotation.Primary)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 DataSourceProxy (io.seata.rm.datasource.DataSourceProxy)2 ConfigurationCustomizer (com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer)1 MybatisMapWrapperFactory (com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory)1 PerformanceInterceptor (com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor)1 OptimisticLockerInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor)1