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
2
3
4
5
6
✨Latest Version
Version: (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
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
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
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