Java Code Examples for org.mybatis.spring.SqlSessionFactoryBean#setMapperLocations()
The following examples show how to use
org.mybatis.spring.SqlSessionFactoryBean#setMapperLocations() .
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: DataSourceConfiguration.java From seata-samples with Apache License 2.0 | 6 votes |
@Bean public SqlSessionFactoryBean sqlSessionFactoryBean(DataSourceProxy dataSourceProxy, MybatisProperties mybatisProperties) { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setDataSource(dataSourceProxy); ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); try { Resource[] mapperLocaltions = resolver.getResources(mybatisProperties.getMapperLocations()[0]); bean.setMapperLocations(mapperLocaltions); if (StringUtils.isNotBlank(mybatisProperties.getConfigLocation())) { Resource[] resources = resolver.getResources(mybatisProperties.getConfigLocation()); bean.setConfigLocation(resources[0]); } } catch (IOException e) { e.printStackTrace(); } return bean; }
Example 2
Source File: DatabaseConfig.java From SO with BSD 2-Clause "Simplified" License | 6 votes |
@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") ); // configuration 은 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(); }
Example 3
Source File: DatabaseConfiguration.java From flowable-engine with Apache License 2.0 | 6 votes |
@Bean public SqlSessionFactory sqlSessionFactory(DataSource dataSource) { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource); try { Properties properties = new Properties(); properties.put("prefix", env.getDataSourcePrefix()); sqlSessionFactoryBean.setConfigurationProperties(properties); sqlSessionFactoryBean .setMapperLocations(ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath:/META-INF/admin-mybatis-mappings/*.xml")); sqlSessionFactoryBean.afterPropertiesSet(); return sqlSessionFactoryBean.getObject(); } catch (Exception e) { throw new RuntimeException("Could not create sqlSessionFactory", e); } }
Example 4
Source File: MybatisConfiguration.java From spring-boot-tutorials with Apache License 2.0 | 5 votes |
@Bean(name = "sqlSessionFactory") public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { final SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource); sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver() .getResources(MAPPER_LOCATION)); return sqlSessionFactoryBean.getObject(); }
Example 5
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 6
Source File: MysqlDataSource1Config.java From mySpringBoot with Apache License 2.0 | 5 votes |
@Bean(name="primarySqlSessionFactory") @Primary public SqlSessionFactory sqlSessionFactory(@Qualifier("primaryDataSource")DataSource primaryDataSource) throws Exception { SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(primaryDataSource); Resource[] mapperLocations = new PathMatchingResourcePatternResolver().getResources("classpath:mapper/db1/*.xml"); sessionFactory.setMapperLocations(mapperLocations); return sessionFactory.getObject(); }
Example 7
Source File: AppConfiguration.java From TAC with MIT License | 5 votes |
@Bean public SqlSessionFactory sqlSessionFactory() throws Exception { SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource()); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); // 声明mapper配置文件路径 sessionFactory.setMapperLocations(resolver.getResources("classpath:/mybatis/*.xml")); return sessionFactory.getObject(); }
Example 8
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 9
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 10
Source File: MybatisConfiguration.java From huanhuan-blog with Apache License 2.0 | 5 votes |
/** * 将mybatis的sqlSessionFactory交给spring管理 */ @Bean public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) throws IOException { PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource); sessionFactory.setMapperLocations(resolver.getResources("classpath:mapper/**/*.xml")); sessionFactory.setTypeAliasesPackage("com.huan.**.model"); return sessionFactory; }
Example 11
Source File: WriteOrReadDatabaseConfig.java From demo-project with MIT License | 5 votes |
/** * 多数据源需要自己设置sqlSessionFactory */ @Bean public SqlSessionFactory sqlSessionFactory() throws Exception { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setDataSource(routingDataSource()); ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); // 实体类对应的位置 bean.setTypeAliasesPackage(typeAliasesPackage); // mybatis的XML的配置 bean.setMapperLocations(resolver.getResources(mapperLocation)); bean.setConfigLocation(resolver.getResource(configLocation)); return bean.getObject(); }
Example 12
Source File: DataSourceConfiguration.java From seata-samples with Apache License 2.0 | 5 votes |
@Bean public SqlSessionFactory sqlSessionFactory(DataSourceProxy dataSourceProxy)throws Exception{ SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSourceProxy); sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver() .getResources("classpath*:/mapper/*.xml")); sqlSessionFactoryBean.setTransactionFactory(new SpringManagedTransactionFactory()); return sqlSessionFactoryBean.getObject(); }
Example 13
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 14
Source File: MybatisConfig.java From kitty with GNU Lesser General Public License v3.0 | 5 votes |
@Bean public SqlSessionFactory sqlSessionFactory() throws Exception { SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource); sessionFactory.setTypeAliasesPackage("com.louis.kitty.*.model"); // 扫描Model PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); sessionFactory.setMapperLocations(resolver.getResources("classpath*:**/sqlmap/*.xml")); // 扫描映射文件 return sessionFactory.getObject(); }
Example 15
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 16
Source File: MyBatisConfig.java From jim-framework with Apache License 2.0 | 5 votes |
@Bean(name = "sqlSessionFactory") public SqlSessionFactory sqlSessionFactoryBean() { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setDataSource(dataSource); bean.setTypeAliasesPackage("com.jim.dao.generated.entity"); //分页插件 PageHelper pageHelper = new PageHelper(); Properties properties = new Properties(); properties.setProperty("dialect", "postgresql"); properties.setProperty("reasonable", "true"); properties.setProperty("supportMethodsArguments", "true"); properties.setProperty("returnPageInfo", "check"); properties.setProperty("params", "count=countSql"); pageHelper.setProperties(properties); //添加插件 bean.setPlugins(new Interceptor[]{pageHelper}); //添加XML目录 ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); try { bean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml")); return bean.getObject(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
Example 17
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 18
Source File: DataSourceConfig.java From seata-samples with Apache License 2.0 | 5 votes |
@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 19
Source File: SeataConfiguration.java From spring-boot-samples with Apache License 2.0 | 5 votes |
@Bean public SqlSessionFactory sqlSessionFactory(DataSourceProxy dataSourceProxy) throws Exception { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSourceProxy); sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver() .getResources("classpath*:/mapper/*.xml")); sqlSessionFactoryBean.setTransactionFactory(new SpringManagedTransactionFactory()); return sqlSessionFactoryBean.getObject(); }
Example 20
Source File: DatabaseConfiguration.java From flowable-engine with Apache License 2.0 | 5 votes |
@Bean public SqlSessionFactory sqlSessionFactory(DataSource dataSource) { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource); String databaseType = initDatabaseType(dataSource); if (databaseType == null) { throw new FlowableException("couldn't deduct database type"); } try { Properties properties = new Properties(); properties.put("prefix", modelerAppProperties.getDataSourcePrefix()); properties.put("blobType", "BLOB"); properties.put("boolValue", "TRUE"); properties.load(this.getClass().getClassLoader().getResourceAsStream("org/flowable/db/properties/" + databaseType + ".properties")); sqlSessionFactoryBean.setConfigurationProperties(properties); sqlSessionFactoryBean .setMapperLocations(ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath:/META-INF/modeler-mybatis-mappings/*.xml")); sqlSessionFactoryBean.afterPropertiesSet(); return sqlSessionFactoryBean.getObject(); } catch (Exception e) { throw new FlowableException("Could not create sqlSessionFactory", e); } }