當前位置: 首頁>>代碼示例>>Java>>正文


Java SqlSessionFactoryBean類代碼示例

本文整理匯總了Java中org.mybatis.spring.SqlSessionFactoryBean的典型用法代碼示例。如果您正苦於以下問題:Java SqlSessionFactoryBean類的具體用法?Java SqlSessionFactoryBean怎麽用?Java SqlSessionFactoryBean使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SqlSessionFactoryBean類屬於org.mybatis.spring包,在下文中一共展示了SqlSessionFactoryBean類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入依賴的package包/類
@Primary
@Bean(name = "test1dbSqlSessionFactory")
public SqlSessionFactory sqlSessionFactory(@Qualifier("test1db") DataSource dataSource) throws Exception {
    SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
    factoryBean.setDataSource(dataSource);
    factoryBean.setTypeAliasesPackage("com.maxplus1.demo.entity");
    factoryBean.setMapperLocations(
            new PathMatchingResourcePatternResolver().getResources("classpath:mapper/test1db/*.xml"));
    return factoryBean.getObject();
}
 
開發者ID:Paleozoic,項目名稱:storm_spring_boot_demo,代碼行數:11,代碼來源:Test1dbConfig.java

示例2: businessSqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入依賴的package包/類
@Bean
@Primary
public SqlSessionFactory businessSqlSessionFactory(@Qualifier("businessDataSource") DruidDataSource businessDataSource) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(businessDataSource);
    //mybatis分頁
    PageHelper pageHelper = new PageHelper();
    Properties props = new Properties();
    props.setProperty("dialect", "mysql");
    props.setProperty("reasonable", "true");
    props.setProperty("supportMethodsArguments", "true");
    props.setProperty("returnPageInfo", "check");
    props.setProperty("params", "count=countSql");
    pageHelper.setProperties(props);
    //添加插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(MAPPERXML_LOCATION));
    return sqlSessionFactoryBean.getObject();
}
 
開發者ID:DomKing,項目名稱:busi-support,代碼行數:21,代碼來源:BusinessDatabaseConfig.java

示例3: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入依賴的package包/類
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource());
    //mybatis分頁
    PageHelper pageHelper = new PageHelper();
    Properties props = new Properties();
    props.setProperty("dialect", "mysql");
    props.setProperty("reasonable", "true");
    props.setProperty("supportMethodsArguments", "true");
    props.setProperty("returnPageInfo", "check");
    props.setProperty("params", "count=countSql");
    pageHelper.setProperties(props); //添加插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:org/xxpay/shop/dao/mapper/*.xml"));
    return sqlSessionFactoryBean.getObject();
}
 
開發者ID:jmdhappy,項目名稱:xxpay-master,代碼行數:19,代碼來源:DruidDataSourceConfig.java

示例4: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入依賴的package包/類
@Bean
public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) throws IOException {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();

    //mybatis配置
    Properties prop = new Properties();
    prop.setProperty("mapUnderscoreToCamelCase", "true");

    sqlSessionFactoryBean.setConfigurationProperties(prop);
    sqlSessionFactoryBean.setTypeAliasesPackage("com.tc.ly.bean");

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = resolver.getResources("classpath:mapper/*.xml");

    sqlSessionFactoryBean.setMapperLocations(resources);
    sqlSessionFactoryBean.setDataSource(dataSource);

    return sqlSessionFactoryBean;
}
 
開發者ID:hadesvip,項目名稱:ly-security,代碼行數:20,代碼來源:MybatisConfig.java

示例5: SqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入依賴的package包/類
@Bean(name = "sqlSessionFactory")
    @Primary
    public SqlSessionFactory SqlSessionFactory(@Qualifier("datasource") DataSource dataSource
            , ApplicationContext applicationContext) throws Exception {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();

        // accur Could not resolve type alias in running jar
        sqlSessionFactoryBean.setVfs(SpringBootVFS.class);

        sqlSessionFactoryBean.setDataSource(dataSource);
        sqlSessionFactoryBean.setMapperLocations(
                applicationContext.getResources("classpath:META-INF/mappers/*.xml")
        );
        sqlSessionFactoryBean.setConfigLocation(
                applicationContext.getResource("classpath:META-INF/mybatis-config.xml")
        );
//        sqlSessionFactoryBean.setConfigurationProperties(mybatisProperties());
        sqlSessionFactoryBean.setTypeAliasesPackage("com.pineone.icbms.so.interfaces.database.model");

        return sqlSessionFactoryBean.getObject();
    }
 
開發者ID:iotoasis,項目名稱:SO,代碼行數:22,代碼來源:DatabaseConfig.java

示例6: sqlSessionFactoryBean

import org.mybatis.spring.SqlSessionFactoryBean; //導入依賴的package包/類
@Bean
public SqlSessionFactoryBean sqlSessionFactoryBean(
        DataSource dataSource,
        ApplicationContext applicationContext) throws IOException {

    SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();

    // 마이바티스가 사용한 DataSource를 등록
    factoryBean.setDataSource(dataSource);

    // 마이바티스 설정파일 위치 설정
    factoryBean.setConfigLocation(applicationContext.getResource("classpath:mybatis-config.xml"));
    factoryBean.setMapperLocations(applicationContext.getResources("classpath:net/andromedarabbit/persistence/mybatis/**/*.xml"));

    factoryBean.setPlugins(new Interceptor[]{
            new PaginationInterceptor(),
            new PaginationResultSetHandlerInterceptor()
    });

    return factoryBean;
}
 
開發者ID:andromedarabbit,項目名稱:mybatis-pagination,代碼行數:22,代碼來源:MyBatisConfig.java

示例7: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入依賴的package包/類
@Bean
@ConditionalOnMissingBean
public SqlSessionFactory sqlSessionFactory() throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(roundRobinDataSouceProxy());
    sqlSessionFactoryBean.setTypeAliasesPackage(this.typeAliasesPackage);
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(this.mapperLocations));
    sqlSessionFactoryBean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);
    return sqlSessionFactoryBean.getObject();
}
 
開發者ID:jinping125,項目名稱:read-write-sever,代碼行數:12,代碼來源:MybatisConfig.java

示例8: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入依賴的package包/類
@Bean  
@ConditionalOnMissingBean  
public SqlSessionFactory sqlSessionFactory() throws Exception {  
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();  
    sqlSessionFactoryBean.setDataSource(roundRobinDataSouceProxy());  
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mybatis/*.xml"));
    sqlSessionFactoryBean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);  
    return sqlSessionFactoryBean.getObject();  
}
 
開發者ID:duanyaxin,項目名稱:springboot-smart,代碼行數:11,代碼來源:Application.java

示例9: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入依賴的package包/類
@Bean public SqlSessionFactory sqlSessionFactory() throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource());
    //mybatis分頁
    PageHelper pageHelper = new PageHelper();
    Properties props = new Properties();
    props.setProperty("dialect", "mysql");
    props.setProperty("reasonable", "true");
    props.setProperty("supportMethodsArguments", "true");
    props.setProperty("returnPageInfo", "check");
    props.setProperty("params", "count=countSql");
    pageHelper.setProperties(props); //添加插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/me/caixin/dao/mapping/**/*.xml"));
    return sqlSessionFactoryBean.getObject();
}
 
開發者ID:cairenjie1985,項目名稱:springBoot-demo,代碼行數:18,代碼來源:MyBatisAutoConfiguration.java

示例10: mockInner

import org.mybatis.spring.SqlSessionFactoryBean; //導入依賴的package包/類
@Test
public void mockInner() throws Exception {
    // mock 騙覆蓋!!!
    SqlSessionFactoryBean factoryBean = mock(SqlSessionFactoryBean.class);
    // 根據mybatisConfig.sqlSessionFactoryBean 最後的try 方法塊. 隻有factoryBean.getObject 可能產生Exception
    // mock factoryBean.getObject 使其返回exception 並定義msg
    when(factoryBean.getObject()).thenThrow(new Exception(" this error is mock exception "));
    // spy 方法可以mock指定方法  而 mock方法產生的則是全部方法代理   兩個都是cglib的代理對象.
    MybatisConfig mybatisConfig = spy(new MybatisConfig());
    // 當調用mybatisConfig.getSqlSessionFactoryBeanInstance時產生mock的factoryBean
    when(mybatisConfig.getSqlSessionFactoryBeanInstance()).thenReturn(factoryBean);
    expectedException.expect(EasyMallTestException.class);
    expectedException.expectMessage("mock exception");

    mybatisConfig.sqlSessionFactoryBean();
}
 
開發者ID:easymall,項目名稱:easymall,代碼行數:17,代碼來源:MybatisConfigTest.java

示例11: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入依賴的package包/類
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource());
    //mybatis分頁
    PageHelper pageHelper = new PageHelper();
    Properties props = new Properties();
    props.setProperty("dialect", "mysql");
    props.setProperty("reasonable", "true");
    props.setProperty("supportMethodsArguments", "true");
    props.setProperty("returnPageInfo", "check");
    props.setProperty("params", "count=countSql");
    pageHelper.setProperties(props); //添加插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:org/xxpay/dal/dao/mapper/*.xml"));
    return sqlSessionFactoryBean.getObject();
}
 
開發者ID:ywtnhm,項目名稱:pay-xxpay-master,代碼行數:19,代碼來源:DruidDataSourceConfig.java

示例12: createSqlSessionFactoryBean

import org.mybatis.spring.SqlSessionFactoryBean; //導入依賴的package包/類
@Bean
public SqlSessionFactoryBean createSqlSessionFactoryBean() throws IOException {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(env.getProperty("mybatis.config-location")));
    PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
    String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + env.getProperty("mybatis.mapper-locations");
    sqlSessionFactoryBean.setMapperLocations(pathMatchingResourcePatternResolver.getResources(packageSearchPath));
    sqlSessionFactoryBean.setDataSource(dataSource());

    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", env.getProperty("pageHelper.reasonable"));
    properties.setProperty("supportMethodsArguments", env.getProperty("pageHelper.supportMethodsArguments"));
    properties.setProperty("returnPageInfo", env.getProperty("pageHelper.returnPageInfo"));
    properties.setProperty("params", env.getProperty("pageHelper.params"));
    pageHelper.setProperties(properties);
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});

    return sqlSessionFactoryBean;
}
 
開發者ID:myopenresources,項目名稱:cc-s,代碼行數:21,代碼來源:MyBatisConfig.java

示例13: read2SqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入依賴的package包/類
/**
 * SqlSessionFactory配置
 *
 * @return
 * @throws Exception
 */
@Bean(name = "read2SqlSessionFactory")
public SqlSessionFactory read2SqlSessionFactory(
        @Qualifier("read2DataSource") DataSource dataSource
) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    // 配置mapper文件位置
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(read2MapperLocations));

    //配置分頁插件
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", "true");
    properties.setProperty("supportMethodsArguments", "true");
    properties.setProperty("returnPageInfo", "check");
    properties.setProperty("params", "count=countSql");
    pageHelper.setProperties(properties);

    //設置插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    return sqlSessionFactoryBean.getObject();
}
 
開發者ID:Lengchuan,項目名稱:SpringBoot-Study,代碼行數:31,代碼來源:Read2DruidDataSourceConfig.java

示例14: read1SqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入依賴的package包/類
/**
 * SqlSessionFactory配置
 *
 * @return
 * @throws Exception
 */
@Bean(name = "read1SqlSessionFactory")
public SqlSessionFactory read1SqlSessionFactory(
        @Qualifier("read1DataSource") DataSource dataSource
) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    // 配置mapper文件位置
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(read1MapperLocations));

    //配置分頁插件
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", "true");
    properties.setProperty("supportMethodsArguments", "true");
    properties.setProperty("returnPageInfo", "check");
    properties.setProperty("params", "count=countSql");
    pageHelper.setProperties(properties);

    //設置插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    return sqlSessionFactoryBean.getObject();
}
 
開發者ID:Lengchuan,項目名稱:SpringBoot-Study,代碼行數:31,代碼來源:Read1DruidDataSourceConfig.java

示例15: masterSqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入依賴的package包/類
/**
 * SqlSessionFactory配置
 *
 * @return
 * @throws Exception
 */
@Bean(name = "masterSqlSessionFactory")
@Primary
public SqlSessionFactory masterSqlSessionFactory(
        @Qualifier("masterDataSource") DataSource dataSource
) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    // 配置mapper文件位置
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(masterMapperLocations));

    //配置分頁插件
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", "true");
    properties.setProperty("supportMethodsArguments", "true");
    properties.setProperty("returnPageInfo", "check");
    properties.setProperty("params", "count=countSql");
    pageHelper.setProperties(properties);

    //設置插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    return sqlSessionFactoryBean.getObject();
}
 
開發者ID:Lengchuan,項目名稱:SpringBoot-Study,代碼行數:32,代碼來源:MasterDruidDataSourceConfig.java


注:本文中的org.mybatis.spring.SqlSessionFactoryBean類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。