Java Code Examples for org.mybatis.spring.SqlSessionFactoryBean#getObject()
The following examples show how to use
org.mybatis.spring.SqlSessionFactoryBean#getObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyBatisConfig.java From RuoYi-Vue with MIT License | 6 votes |
@Bean public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage"); String mapperLocations = env.getProperty("mybatis.mapperLocations"); String configLocation = env.getProperty("mybatis.configLocation"); typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage); VFS.addImplClass(SpringBootVFS.class); final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource); sessionFactory.setTypeAliasesPackage(typeAliasesPackage); sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations)); sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation)); return sessionFactory.getObject(); }
Example 2
Source File: CourseDbConfig.java From springboot-course with GNU General Public License v3.0 | 5 votes |
@Bean(name = "courseSqlSessionFactory") @Primary public SqlSessionFactory courseSqlSessionFactory(@Qualifier("courseDataSource") DataSource dataSource) throws Exception { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setDataSource(dataSource); return bean.getObject(); }
Example 3
Source File: MasterDataSourceConfig.java From springboot-learning-example with Apache License 2.0 | 5 votes |
@Bean(name = "masterSqlSessionFactory") @Primary public SqlSessionFactory masterSqlSessionFactory(@Qualifier("masterDataSource") DataSource masterDataSource) throws Exception { final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(masterDataSource); sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver() .getResources(MasterDataSourceConfig.MAPPER_LOCATION)); return sessionFactory.getObject(); }
Example 4
Source File: MyBatisConfiguration.java From multi-mybatis-demo with MIT License | 5 votes |
@Bean(name = ANOTHER_SESSION_FACTORY, destroyMethod = "") public SqlSessionFactoryBean censoSqlSessionFactory(@Named(DatabaseConfiguration.ANOTHER_DATASOURCE) final DataSource anotherDataSource) throws Exception { final SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(anotherDataSource); final SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBean.getObject(); sqlSessionFactory.getConfiguration().addMapper(AnotherMapper.class); // Various other SqlSessionFactory settings return sqlSessionFactoryBean; }
Example 5
Source File: SeataDataSourceAutoConfig.java From seata-samples with Apache License 2.0 | 5 votes |
/** * init mybatis sqlSessionFactory * @Param: dataSourceProxy datasource proxy * @Return: DataSourceProxy datasource proxy */ @Bean public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); factoryBean.setDataSource(dataSource); factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver() .getResources("classpath*:/mapper/*.xml")); return factoryBean.getObject(); }
Example 6
Source File: DbConfiguration.java From flower with Apache License 2.0 | 5 votes |
@Bean("dbSessionFactory") public SqlSessionFactory mySessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setDataSource(dataSource); bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/aggregate/*.xml")); return bean.getObject(); }
Example 7
Source File: DatabaseConfig.java From java-master with Apache License 2.0 | 5 votes |
/** * mybatis配置的核心bean */ @Bean public SqlSessionFactory mysqlSqlSessionFactory(DataSource dataSource) throws Exception { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource); final String mapperLocation = "classpath:mapper/**/*.xml"; sqlSessionFactoryBean.setMapperLocations(resolver.getResources(mapperLocation)); String configLocation = "classpath:mybatis-config.xml"; sqlSessionFactoryBean.setConfigLocation(resolver.getResources(configLocation)[0]); return sqlSessionFactoryBean.getObject(); }
Example 8
Source File: DataSource1Config.java From springboot-guide with Apache License 2.0 | 5 votes |
/** * 创建 SqlSessionFactory */ @Bean(name = "db1SqlSessionFactory") @Primary public SqlSessionFactory testSqlSessionFactory(@Qualifier("db1DataSource") DataSource dataSource) throws Exception { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setDataSource(dataSource); // bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/db1/*.xml")); return bean.getObject(); }
Example 9
Source File: SeataAutoConfig.java From seata-samples with Apache License 2.0 | 5 votes |
/** * init mybatis sqlSessionFactory * @Param: dataSourceProxy datasource proxy * @Return: DataSourceProxy datasource proxy */ @Bean public SqlSessionFactory sqlSessionFactory(DataSourceProxy dataSourceProxy) throws Exception { SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); factoryBean.setDataSource(dataSourceProxy); factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver() .getResources("classpath*:/mapper/*.xml")); factoryBean.setTransactionFactory(new JdbcTransactionFactory()); return factoryBean.getObject(); }
Example 10
Source File: MysqlDatasourceConfig.java From SpringAll with MIT License | 5 votes |
@Bean(name = "mysqlSqlSessionFactory") @Primary public SqlSessionFactory mysqlSqlSessionFactory(@Qualifier("mysqldatasource") DataSource dataSource) throws Exception { final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource); //如果不使用xml的方式配置mapper,则可以省去下面这行mapper location的配置。 sessionFactory.setMapperLocations( new PathMatchingResourcePatternResolver().getResources(MysqlDatasourceConfig.MAPPER_LOCATION)); return sessionFactory.getObject(); }
Example 11
Source File: MybatisConfig.java From light-reading-cloud with MIT License | 5 votes |
/** 工厂配置 */ @Bean public SqlSessionFactory sqlSessionFactoryBean(@Qualifier("bookCenterDataSource") DataSource dataSource) throws Exception { // 设置数据源 SqlSessionFactoryBean factory = new SqlSessionFactoryBean(); factory.setDataSource(dataSource); // 添加XML映射 ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); factory.setMapperLocations(resolver.getResources(MAPPER_LOCATIONS)); //添加插件 factory.setPlugins(new Interceptor[]{ this.getPageHelper() }); return factory.getObject(); }
Example 12
Source File: Test2dbConfig.java From storm_spring_boot_demo with MIT License | 5 votes |
@Bean(name = "test2dbSqlSessionFactory") public SqlSessionFactory sqlSessionFactory(@Qualifier("test2db") DataSource dataSource) throws Exception { SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); factoryBean.setDataSource(dataSource); factoryBean.setTypeAliasesPackage("com.maxplus1.demo.entity"); factoryBean.setMapperLocations( new PathMatchingResourcePatternResolver().getResources("classpath:mapper/test2db/*.xml")); return factoryBean.getObject(); }
Example 13
Source File: MysqlDataSource2Config.java From mySpringBoot with Apache License 2.0 | 5 votes |
@Bean(name = "secondSqlSessionFactory") public SqlSessionFactory sqlSessionFactory() throws Exception { SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource()); Resource[] mapperLocations = new PathMatchingResourcePatternResolver().getResources("classpath:mapper/db2/*.xml"); sessionFactory.setMapperLocations(mapperLocations); return sessionFactory.getObject(); }
Example 14
Source File: SeataAutoConfig.java From demo-seata-springcloud with Apache License 2.0 | 5 votes |
/** * 初始化mybatis sqlSessionFactory * * @param dataSourceProxy * @return * @throws Exception * @author sly * @time 2019年6月11日 */ @Bean public SqlSessionFactory sqlSessionFactory(DataSourceProxy dataSourceProxy) throws Exception { SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); factoryBean.setDataSource(dataSourceProxy); factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml")); factoryBean.setTypeAliasesPackage("com.sly.seata.common.model"); factoryBean.setTransactionFactory(new JdbcTransactionFactory()); return factoryBean.getObject(); }
Example 15
Source File: MybatisConfig.java From light-reading-cloud with MIT License | 5 votes |
/** 工厂配置 */ @Bean public SqlSessionFactory sqlSessionFactoryBean(@Qualifier("bookCenterDataSource") DataSource dataSource) throws Exception { // 设置数据源 SqlSessionFactoryBean factory = new SqlSessionFactoryBean(); factory.setDataSource(dataSource); // 添加XML映射 ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); factory.setMapperLocations(resolver.getResources(MAPPER_LOCATIONS)); //添加插件 factory.setPlugins(new Interceptor[]{ this.getPageHelper() }); return factory.getObject(); }
Example 16
Source File: MySqlDatasourceConfiguration.java From pmq with Apache License 2.0 | 5 votes |
@Bean(name = "mysqlSessionFactory") @Primary public SqlSessionFactory sqlSessionFactory(@Qualifier("mysqlDataSource") DataSource dataSource,SoaConfig soaConfig) throws Exception { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setPlugins(new Interceptor[] {new CatMybatisPlugin(soaConfig)}); bean.setDataSource(dataSource); bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MAPPER_XML_PATH)); bean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true); return bean.getObject(); }
Example 17
Source File: ShardingDataSourceConfig.java From open-capacity-platform with Apache License 2.0 | 5 votes |
@Bean(name = "sqlSessionFactory") public SqlSessionFactory testSqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setDataSource(dataSource); bean.setMapperLocations( new PathMatchingResourcePatternResolver().getResources("classpath*:com/central/**/dao/*.xml")); return bean.getObject(); }
Example 18
Source File: MybatisConfigurer.java From mySpringBoot with Apache License 2.0 | 5 votes |
@Bean public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception { SqlSessionFactoryBean factory = new SqlSessionFactoryBean(); factory.setDataSource(dataSource); factory.setTypeAliasesPackage(ProjectConstant.MODEL_PACKAGE); // 添加XML目录 ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); factory.setMapperLocations(resolver.getResources("classpath:mapper/*.xml")); return factory.getObject(); }
Example 19
Source File: MyBatisOAuthConfig.java From mini-platform with MIT License | 5 votes |
@Bean @Primary public SqlSessionFactory sqlSessionFactoryBeanForOAuth(@Qualifier("dataSourceOAuth") DataSource dataSource) throws Exception { SqlSessionFactoryBean factory = new SqlSessionFactoryBean(); factory.setDataSource(dataSource); factory.setTypeAliasesPackage("com.github.hiling.auth.model"); ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); factory.setMapperLocations(resolver.getResources("classpath:mapper/*.xml")); return factory.getObject(); }
Example 20
Source File: SpringAnnotationTest.java From Mapper with MIT License | 4 votes |
@Bean public SqlSessionFactory sqlSessionFactory() throws Exception { SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource()); return sessionFactory.getObject(); }