Easy-Es Easy-Es
💋Home
  • v2.0.0(current version)
  • What's New

    • What' s New In Easy-Es v2.0.0?
  • history version

    • v1.x.x
  • Upgrade guide

    • Upgrade to 2.x.x instructions
💖Support
  • OS Community
  • Recommend Goods
  • Project PPT (opens new window)
  • Project introduction
  • Project members
  • PR
Join
Customer
  • Doc-Apis (opens new window)
  • Fitness plan automatic generation system (opens new window)
  • Vuepress-theme-vdoing (opens new window)
  • Gitee (opens new window)
  • Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)

adv display by random ❤️become sponsor
💋Home
  • v2.0.0(current version)
  • What's New

    • What' s New In Easy-Es v2.0.0?
  • history version

    • v1.x.x
  • Upgrade guide

    • Upgrade to 2.x.x instructions
💖Support
  • OS Community
  • Recommend Goods
  • Project PPT (opens new window)
  • Project introduction
  • Project members
  • PR
Join
Customer
  • Doc-Apis (opens new window)
  • Fitness plan automatic generation system (opens new window)
  • Vuepress-theme-vdoing (opens new window)
  • Gitee (opens new window)
  • Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)
  • Quick start

    • Introduction.md
    • Applicable scene
    • Worry free
    • Avoid pit
    • Quick start
    • Springboot demo
    • Spring Integration Guide
      • Introducing Dependencies
      • 1. Configure XML Beans as Needed
      • 2. Configure Using Easy-Es-Spring Scanning Class
      • 3. Configure via Scanning Annotation (Recommended)
      • Usage
    • Solon Integration Guide
    • Config
    • Annotation
  • Core function

    • Condition constructor

      • Introduction of Wrapper
      • Index wrapper
      • Select wrapper
      • Update wrapper
    • Index CRUD

      • Index hosting model
      • Index CRUD
    • Data CRUD

      • Data synchronization solutions
      • Data CRUD
    • Multiple data sources support
    • Dynamic indexing support
    • Four nested query
    • Chain call
  • Extended function

    • Mixed query
    • Origin query
    • Page
    • Nested
    • Join parent child
    • Get DSL
    • ExecuteDSL
    • Execute SQL
    • Custom RequestOptions
    • Custom default method
  • High-level syntax

    • Field filtering
    • Sort
    • Aggregation
    • Match&fuzzy match
    • Weight
    • Highlight
    • Geo
    • IP
  • Plugin

    • Plugin
  • Other

    • Faq
    • Difference from MP
    • MySQL and EE syntax comparison
    • Update log
    • Update plan
    • Copyright
    • Thanks
  • v2.xDoc
  • Quick start
LaoHan
2025-02-03
目录

Spring Integration Guide

# Spring Integration Guide

The usage of Spring is similar to the previous chapter on Spring Boot. It is important to note that the dependencies introduced in Spring are different from those in Spring Boot, and manual configuration of XML beans is required.

# Introducing Dependencies

<dependency>
    <groupId>org.dromara.easy-es</groupId>
    <artifactId>easy-es-spring</artifactId>
    <!-- Use the latest supported version, must be greater than or equal to 2.1.0 -->
    <version>2.1.0</version>
</dependency>
1
2
3
4
5
6

✨Latest Version Version: Maven Central (opens new window)

# 1. Configure XML Beans as Needed

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- The following properties are configured as needed -->
    <bean id="easyEsProperties" class="org.dromara.easyes.common.property.EasyEsProperties">
        <property name="enable" value="true"/>
        <property name="address" value="127.0.0.1:9200"/>
        <property name="keepAliveMillis" value="18000"/>
        <property name="globalConfig.IKunMode" value="true"/>
        <property name="globalConfig.processIndexMode" value="MANUAL"/>
        <property name="globalConfig.asyncProcessIndexBlocking" value="true"/>
        <property name="globalConfig.printDsl" value="true"/>
        <property name="globalConfig.dbConfig.mapUnderscoreToCamelCase" value="true"/>
        <property name="globalConfig.dbConfig.idType" value="CUSTOMIZE"/>
        <property name="globalConfig.dbConfig.fieldStrategy" value="NOT_EMPTY"/>
        <property name="globalConfig.dbConfig.refreshPolicy" value="IMMEDIATE"/>
        <property name="globalConfig.dbConfig.enableTrackTotalHits" value="true"/>
    </bean>

    <!-- Multi-data source configuration -->
    <bean id="easyEsDynamicProperties" class="org.dromara.easyes.common.property.EasyEsDynamicProperties">

    </bean>

    <!-- Mapper configuration, basePackage path should be configured according to the actual mapper location -->
    <bean id="mapperScannerConfigurer" class="org.dromara.easyes.spring.MapperScannerConfigurer">
        <property name="basePackage" value="org.dromara.easyes.test.mapper"/>
    </bean>
</beans>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

# 2. Configure Using Easy-Es-Spring Scanning Class

import org.dromara.easyes.common.property.EasyEsDynamicProperties;
import org.dromara.easyes.common.property.EasyEsProperties;
import org.dromara.easyes.spring.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * Alternative to XML configuration in Spring
 * @author MoJie
 * @since 2.1.0
 */
@Configuration
public class EasyEsSpringConfig {

    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        // Mapper configuration, basePackage path should be configured according to the actual mapper location
        mapperScannerConfigurer.setBasePackage("org.dromara.easyes.test.mapper");
        return mapperScannerConfigurer;
    }

    @Bean
    public EasyEsProperties easyEsProperties() {
        EasyEsProperties easyEsProperties = new EasyEsProperties();
        // The following are Easy-Es configuration items
        easyEsProperties.setAddress("127.0.0.1:9200");
        return easyEsProperties;
    }

    @Bean
    public EasyEsDynamicProperties easyEsDynamicProperties() {
        EasyEsDynamicProperties easyEsDynamicProperties = new EasyEsDynamicProperties();
        // Multi-data source configuration
        Map<String, EasyEsProperties> datasource = new HashMap<>();
        // You can configure multiple data sources here, and specify the data source in the mapper via the @EsDS("key") annotation
        easyEsDynamicProperties.setDatasource(datasource);
        return easyEsDynamicProperties;
    }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

# 3. Configure via Scanning Annotation (Recommended)

import org.dromara.easyes.common.property.EasyEsDynamicProperties;
import org.dromara.easyes.common.property.EasyEsProperties;
import org.dromara.easyes.spring.annotation.EsMapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * Alternative to XML configuration in Spring
 * @author MoJie
 * @since 2.1.0
 */
@Configuration
@EsMapperScan("org.dromara.easyes.test.mapper")
public class EasyEsSpringConfig {

    @Bean
    public EasyEsProperties easyEsProperties() {
        EasyEsProperties easyEsProperties = new EasyEsProperties();
        // The following are Easy-Es configuration items
        easyEsProperties.setAddress("127.0.0.1:9200");
        return easyEsProperties;
    }

    @Bean
    public EasyEsDynamicProperties easyEsDynamicProperties() {
        EasyEsDynamicProperties easyEsDynamicProperties = new EasyEsDynamicProperties();
        // Multi-data source configuration
        Map<String, EasyEsProperties> datasource = new HashMap<>();
        // You can configure multiple data sources here, and specify the data source in the mapper via the @EsDS("key") annotation
        easyEsDynamicProperties.setDatasource(datasource);
        return easyEsDynamicProperties;
    }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

# Usage

Inject the Mapper directly where needed using @Autowired or @Resource. There is no difference in usage compared to Spring Boot, and the same applies to other aspects.

Help us improve this document (opens new window)
Last update: 2025/02/05
Springboot demo
Solon Integration Guide

← Springboot demo Solon Integration Guide→

Theme by Vdoing | Copyright © 2021-2025 LaoHan | Zhejiang ICP No. 2022020479 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式