org.apache.ibatis.io.VFS Java Examples

The following examples show how to use org.apache.ibatis.io.VFS. 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 vote down vote up
@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: SqlSessionFactoryConfig.java    From mybatis.flying with Apache License 2.0 6 votes vote down vote up
@Bean(name = "sqlSessionFactory")
@Primary
public SqlSessionFactoryBean createSqlSessionFactoryBean() throws IOException {
	SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
	/** 设置datasource */
	sqlSessionFactoryBean.setDataSource(dataSource1);
	VFS.addImplClass(SpringBootVFS.class);
	/** 设置mybatis configuration 扫描路径 */
	sqlSessionFactoryBean.setConfigLocation(new ClassPathResource("Configuration.xml"));
	/** 设置typeAlias 包扫描路径 */
	sqlSessionFactoryBean.setTypeAliasesPackage("indi.mybatis.flying");
	/** 添加mapper 扫描路径 */
	PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
	Resource[] ra1 = resolver.getResources("classpath*:indi/mybatis/flying/mapper*/*.xml");
	sqlSessionFactoryBean.setMapperLocations(ra1); // 扫描映射文件
	return sqlSessionFactoryBean;
}
 
Example #3
Source File: SqlSessionFactory2Config.java    From mybatis.flying with Apache License 2.0 6 votes vote down vote up
@Bean(name = "sqlSessionFactory2")
@Primary
public SqlSessionFactoryBean createSqlSessionFactory2Bean() throws IOException {
	SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
	/** 设置datasource */
	sqlSessionFactoryBean.setDataSource(dataSource2);
	VFS.addImplClass(SpringBootVFS.class);
	/** 设置mybatis configuration 扫描路径 */
	sqlSessionFactoryBean.setConfigLocation(new ClassPathResource("Configuration.xml"));
	/** 设置typeAlias 包扫描路径 */
	sqlSessionFactoryBean.setTypeAliasesPackage("indi.mybatis.flying");
	/** 添加mapper 扫描路径 */
	PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
	Resource[] ra1 = resolver.getResources("classpath*:indi/mybatis/flying/mapper*/*.xml");
	sqlSessionFactoryBean.setMapperLocations(ra1); // 扫描映射文件
	return sqlSessionFactoryBean;
}
 
Example #4
Source File: MaxKeyApplication.java    From MaxKey with Apache License 2.0 6 votes vote down vote up
/**
 * @param args args
 */
public static void main(String[] args) {
    _logger.info("Start MaxKeyApplication ...");
    
    VFS.addImplClass(SpringBootVFS.class);
    ConfigurableApplicationContext applicationContext = 
            SpringApplication.run(MaxKeyApplication.class, args);
    InitializeContext initWebContext = new InitializeContext(applicationContext);
    try {
        initWebContext.init(null);
    } catch (ServletException e) {
        e.printStackTrace();
        _logger.error("", e);
    }
    _logger.info("MaxKey at " + new Date(applicationContext.getStartupDate()));
    _logger.info("MaxKey Server Port "
            +   applicationContext.getBean(ApplicationConfig.class).getPort());
    _logger.info("MaxKey started.");
}
 
Example #5
Source File: MyBatisConfiguration.java    From Aooms with Apache License 2.0 5 votes vote down vote up
@Bean
ConfigurationCustomizer mybatisConfigurationCustomizer() {
    return new ConfigurationCustomizer() {

        @Override
        public void customize(org.apache.ibatis.session.Configuration configuration) {
            // HashSet<MappedStatement> mappedStatements = new HashSet<MappedStatement>(configuration.getMappedStatements());

            /*SqlSource sqlSource = new SqlSource() {
                @Override
                public BoundSql getBoundSql(Object parameterObject) {
                    return new BoundSql(configuration,"nosqlscript",null,null);
                }
            };

            MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, MyBatisConst.MS_RECORD_INSERT, sqlSource, SqlCommandType.INSERT);
            configuration.addMappedStatement(statementBuilder.build());
            */
            // 修改默认vfs, 解决jar包 mapper.xml 不加载问题
            VFS.addImplClass(SpringBootVFS.class);
            //configuration.setVfsImpl(SpringBootVFS.class);

            // 设置map属性空值时仍返回数据
            configuration.setCallSettersOnNulls(true);

            RecordMappedStatmentFactory recordMappedStatmentFactory = new RecordMappedStatmentFactory(configuration);
            configuration.addMappedStatement(recordMappedStatmentFactory.getRecordInsertMappedStatment());
            configuration.addMappedStatement(recordMappedStatmentFactory.getRecordUpdateMappedStatment());
            configuration.addMappedStatement(recordMappedStatmentFactory.getRecordDeleteMappedStatment());
            configuration.addMappedStatement(recordMappedStatmentFactory.getRecordFindByPkMappedStatment());

        }
    };
}