mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-06 09:09:13 +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
|
||||
public EsClientUtils esClientUtils(
|
||||
EasyEsProperties properties, EasyEsDynamicProperties dynamicProperties) {
|
||||
public EsClientUtils esClientUtils(EasyEsProperties properties, EasyEsDynamicProperties dynamicProperties) {
|
||||
EsClientUtils esClientUtils = new EsClientUtils();
|
||||
Map<String, EasyEsProperties> datasourceMap = dynamicProperties.getDatasource();
|
||||
if (CollectionUtils.isEmpty(datasourceMap)) {
|
||||
|
||||
@ -21,7 +21,7 @@ import java.util.Optional;
|
||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@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 {
|
||||
|
||||
/**
|
||||
|
||||
@ -62,7 +62,8 @@ public class MapperScannerConfigurer
|
||||
prc.postProcessBeanFactory(factory);
|
||||
}
|
||||
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
|
||||
**/
|
||||
public class MapperScannerRegister implements ImportBeanDefinitionRegistrar, EnvironmentAware {
|
||||
|
||||
private Environment environment;
|
||||
|
||||
@Override
|
||||
@ -60,8 +61,8 @@ public class MapperScannerRegister implements ImportBeanDefinitionRegistrar, Env
|
||||
* 使用了jdk动态代理,需要确定注册的实际interface class,就需要通过BeanDefinition来追加属性,
|
||||
* 当前使用到了spring的构造
|
||||
*
|
||||
* @param registry spring bean扫码注册器
|
||||
* @param basePackages 扫码的包
|
||||
* @param registry spring bean扫描注册器
|
||||
* @param basePackages 扫描的包
|
||||
*/
|
||||
void registerBeanDefinitions(BeanDefinitionRegistry registry, String beanName, String... basePackages) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class);
|
||||
|
||||
@ -2,6 +2,7 @@ package org.dromara.easyes.spring.config;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import org.dromara.easyes.common.constants.BaseEsConstants;
|
||||
import org.dromara.easyes.common.property.EasyEsDynamicProperties;
|
||||
import org.dromara.easyes.common.property.EasyEsProperties;
|
||||
import org.dromara.easyes.common.strategy.AutoProcessIndexStrategy;
|
||||
@ -20,17 +21,20 @@ import org.springframework.util.Assert;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Easy-Es Spring配置类
|
||||
* @author MoJie
|
||||
* @since 2.0
|
||||
*/
|
||||
@Setter
|
||||
@Configuration
|
||||
public class EasyEsConfiguration implements InitializingBean, EnvironmentAware {
|
||||
|
||||
private Environment environment;
|
||||
|
||||
@Setter
|
||||
@Autowired(required = false)
|
||||
private EasyEsProperties easyEsProperties;
|
||||
|
||||
@Setter
|
||||
@Autowired(required = false)
|
||||
private EasyEsDynamicProperties easyEsDynamicProperties;
|
||||
|
||||
@ -39,14 +43,21 @@ public class EasyEsConfiguration implements InitializingBean, EnvironmentAware {
|
||||
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() {
|
||||
Boolean enable = environment.getProperty("easy-es.enable", Boolean.class, Boolean.TRUE);
|
||||
Boolean enable = environment.getProperty(BaseEsConstants.ENABLE_PREFIX, Boolean.class, Boolean.TRUE);
|
||||
if (enable) {
|
||||
Assert.notNull(this.easyEsProperties, "easyEsProperties must is A bean. easy-es配置类必须给配置一个bean");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public IndexStrategyFactory indexStrategyFactory() {
|
||||
return new IndexStrategyFactory();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user