mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-06 17:18:57 +08:00
Merge branch 'feature-3.0' of https://gitee.com/dromara/easy-es into feature-3.0
This commit is contained in:
commit
f5ac2ffabb
@ -51,8 +51,7 @@ public class EsAutoConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public EsClientUtils esClientUtils(
|
public EsClientUtils esClientUtils(EasyEsProperties properties, EasyEsDynamicProperties dynamicProperties) {
|
||||||
EasyEsProperties properties, EasyEsDynamicProperties dynamicProperties) {
|
|
||||||
EsClientUtils esClientUtils = new EsClientUtils();
|
EsClientUtils esClientUtils = new EsClientUtils();
|
||||||
Map<String, EasyEsProperties> datasourceMap = dynamicProperties.getDatasource();
|
Map<String, EasyEsProperties> datasourceMap = dynamicProperties.getDatasource();
|
||||||
if (CollectionUtils.isEmpty(datasourceMap)) {
|
if (CollectionUtils.isEmpty(datasourceMap)) {
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import java.util.Optional;
|
|||||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||||
**/
|
**/
|
||||||
@Component
|
@Component
|
||||||
@Condition(onBean = ElasticsearchClient.class, onProperty = "${easy-es.enable:true} = true && ${easy-es.address:x} != x")
|
@Condition(onBean = ElasticsearchClient.class, onProperty = "${easy-es.enable:true} = true")
|
||||||
public class IndexStrategyFactory implements LifecycleBean {
|
public class IndexStrategyFactory implements LifecycleBean {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -62,7 +62,8 @@ public class MapperScannerConfigurer
|
|||||||
prc.postProcessBeanFactory(factory);
|
prc.postProcessBeanFactory(factory);
|
||||||
}
|
}
|
||||||
PropertyValues values = mapperScannerBean.getPropertyValues();
|
PropertyValues values = mapperScannerBean.getPropertyValues();
|
||||||
this.basePackage = getPropertyValue("basePackage", values);
|
// 如果在环境变量中取扫描的包,需要从easy-es.mappers进行取值,与mybatis配置mapper相似,但这里不做配置推荐
|
||||||
|
this.basePackage = getPropertyValue("easy-es.mappers", values);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 取变量
|
// 取变量
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import static org.dromara.easyes.common.constants.BaseEsConstants.COMMA;
|
|||||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||||
**/
|
**/
|
||||||
public class MapperScannerRegister implements ImportBeanDefinitionRegistrar, EnvironmentAware {
|
public class MapperScannerRegister implements ImportBeanDefinitionRegistrar, EnvironmentAware {
|
||||||
|
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -60,8 +61,8 @@ public class MapperScannerRegister implements ImportBeanDefinitionRegistrar, Env
|
|||||||
* 使用了jdk动态代理,需要确定注册的实际interface class,就需要通过BeanDefinition来追加属性,
|
* 使用了jdk动态代理,需要确定注册的实际interface class,就需要通过BeanDefinition来追加属性,
|
||||||
* 当前使用到了spring的构造
|
* 当前使用到了spring的构造
|
||||||
*
|
*
|
||||||
* @param registry spring bean扫码注册器
|
* @param registry spring bean扫描注册器
|
||||||
* @param basePackages 扫码的包
|
* @param basePackages 扫描的包
|
||||||
*/
|
*/
|
||||||
void registerBeanDefinitions(BeanDefinitionRegistry registry, String beanName, String... basePackages) {
|
void registerBeanDefinitions(BeanDefinitionRegistry registry, String beanName, String... basePackages) {
|
||||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class);
|
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class);
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package org.dromara.easyes.spring.config;
|
|||||||
|
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.dromara.easyes.common.constants.BaseEsConstants;
|
||||||
import org.dromara.easyes.common.property.EasyEsDynamicProperties;
|
import org.dromara.easyes.common.property.EasyEsDynamicProperties;
|
||||||
import org.dromara.easyes.common.property.EasyEsProperties;
|
import org.dromara.easyes.common.property.EasyEsProperties;
|
||||||
import org.dromara.easyes.common.strategy.AutoProcessIndexStrategy;
|
import org.dromara.easyes.common.strategy.AutoProcessIndexStrategy;
|
||||||
@ -20,17 +21,20 @@ import org.springframework.util.Assert;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Easy-Es Spring配置类
|
||||||
* @author MoJie
|
* @author MoJie
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
@Setter
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class EasyEsConfiguration implements InitializingBean, EnvironmentAware {
|
public class EasyEsConfiguration implements InitializingBean, EnvironmentAware {
|
||||||
|
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
|
|
||||||
|
@Setter
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private EasyEsProperties easyEsProperties;
|
private EasyEsProperties easyEsProperties;
|
||||||
|
|
||||||
|
@Setter
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private EasyEsDynamicProperties easyEsDynamicProperties;
|
private EasyEsDynamicProperties easyEsDynamicProperties;
|
||||||
|
|
||||||
@ -39,14 +43,21 @@ public class EasyEsConfiguration implements InitializingBean, EnvironmentAware {
|
|||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当当前配置类注册为bean完成后触发,校验easy-es配置是否存在,
|
||||||
|
* 如果easy-es.enable: false, 那么不进行校验和抛出异常
|
||||||
|
* 默认情况下引入了easy-es是需要配置的,即easy-es.enable:true
|
||||||
|
* 如果不需要easy-es,那么自行配置为false
|
||||||
|
* @author MoJie
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
Boolean enable = environment.getProperty("easy-es.enable", Boolean.class, Boolean.TRUE);
|
Boolean enable = environment.getProperty(BaseEsConstants.ENABLE_PREFIX, Boolean.class, Boolean.TRUE);
|
||||||
if (enable) {
|
if (enable) {
|
||||||
Assert.notNull(this.easyEsProperties, "easyEsProperties must is A bean. easy-es配置类必须给配置一个bean");
|
Assert.notNull(this.easyEsProperties, "easyEsProperties must is A bean. easy-es配置类必须给配置一个bean");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public IndexStrategyFactory indexStrategyFactory() {
|
public IndexStrategyFactory indexStrategyFactory() {
|
||||||
return new IndexStrategyFactory();
|
return new IndexStrategyFactory();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user