Merge branch 'feature-3.0' of https://gitee.com/dromara/easy-es into feature-3.0

This commit is contained in:
xpc 2025-04-12 20:42:26 +08:00
commit f5ac2ffabb
5 changed files with 21 additions and 9 deletions

View File

@ -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)) {

View File

@ -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 {
/**

View File

@ -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);
}
// 取变量

View File

@ -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);

View File

@ -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();