栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

elasticsearch整合mybatis

elasticsearch整合mybatis

elasticsearch整合mybatis

1.在pom文件中添加依赖2.配置文件中添加配置创建数据库配置类

1.在pom文件中添加依赖

    org.elasticsearch.plugin
    x-pack-sql-jdbc

2.配置文件中添加配置
datasource
   basedata
	 es:
      url: jdbc:es://ip:port
      driverClassName: org.elasticsearch.xpack.sql.jdbc.EsDriver
      initialSize: 5
      minIdle: 1
      maxActive: 20
      maxWait: 60000
      timeBetweenEvictionRunsMillis: 60000
      minEvictableIdleTimeMillis: 300000
      validationQuery: SELECT 1
      testWhileIdle: true
      testOnBorrow: false
      testOnReturn: false
创建数据库配置类
@Configuration
@MapperScan(basePackages ="gep.dao.mapper.es",sqlSessionFactoryRef ="sqlSessionFactoryForEs")
public class EsXpackMybatisConfig {


    @Autowired
    PageInterceptor interceptor;

    @Bean(name = "esDataSource", destroyMethod = "close", initMethod = "init")
    @ConfigurationProperties(prefix = "datasource.database.es")
    public DruidDataSource esDataSource() {
        return new DruidDataSource();
    }

    @Bean("sqlSessionFactoryForEs")
    public SqlSessionFactory sqlSessionFactoryForEs(@Qualifier("esDataSource") DataSource dataSource) throws Exception {
        SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
        sessionFactoryBean.setDataSource(dataSource);
        PageAutoDialect.registerDialectAlias("es", MySqlDialect.class);
   sessionFactoryBean.setPlugins(new Interceptor[]{interceptor});
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        Resource[] esResources = resolver.getResources("classpath:mapper/es/*.xml");
        sessionFactoryBean.setMapperLocations(esResources);
        return sessionFactoryBean.getObject(); 
        }
    @Bean("sqlSessionTemplateForEs")
    public SqlSessionTemplate sqlSessionTemplateForEs(@Qualifier("sqlSessionFactoryForEs") SqlSessionFactory sqlSessionFactory) {
        return new SqlSessionTemplate(sqlSessionFactory);
    }
}```
        





转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/711316.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号