mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-07 09:39:04 +08:00
commit
e0f12c18ce
@ -15,7 +15,6 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
<maven-jar-plugin.version>3.2.2</maven-jar-plugin.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -30,21 +29,4 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<!--java getImplementationVersion获取版本号-->
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<version>${maven-jar-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package cn.easyes.starter.register;
|
package cn.easyes.starter.register;
|
||||||
|
|
||||||
|
import cn.easyes.common.utils.EEVersionUtil;
|
||||||
import cn.easyes.common.utils.LogUtils;
|
import cn.easyes.common.utils.LogUtils;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
import org.springframework.context.EnvironmentAware;
|
import org.springframework.context.EnvironmentAware;
|
||||||
@ -46,8 +47,7 @@ public class MapperScannerRegister implements ImportBeanDefinitionRegistrar, Res
|
|||||||
//@author dazer
|
//@author dazer
|
||||||
boolean banner = Optional.ofNullable(environment.getProperty(ENABLE_BANNER)).map(Boolean::parseBoolean).orElse(Boolean.TRUE);
|
boolean banner = Optional.ofNullable(environment.getProperty(ENABLE_BANNER)).map(Boolean::parseBoolean).orElse(Boolean.TRUE);
|
||||||
if (banner) {
|
if (banner) {
|
||||||
String versionStr = Optional.ofNullable(MapperScannerRegister.class.getPackage().getImplementationVersion()).
|
String versionStr = EEVersionUtil.getJarVersion(this.getClass());
|
||||||
orElse("unknown");
|
|
||||||
System.out.println("\n" +
|
System.out.println("\n" +
|
||||||
"___ _ _ ___\n" +
|
"___ _ _ ___\n" +
|
||||||
" | __| __ _ ___ | || | ___ | __| ___\n" +
|
" | __| __ _ ___ | || | ___ | __| ___\n" +
|
||||||
@ -56,7 +56,7 @@ public class MapperScannerRegister implements ImportBeanDefinitionRegistrar, Res
|
|||||||
"_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_| \"\"\"\"|_| |_|\"\"\"\"\"|_|\"\"\"\"\"|\n" +
|
"_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_| \"\"\"\"|_| |_|\"\"\"\"\"|_|\"\"\"\"\"|\n" +
|
||||||
"\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\n" +
|
"\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\n" +
|
||||||
"--------------------------xpc-------------------------->");
|
"--------------------------xpc-------------------------->");
|
||||||
System.out.println(":: easy-es :: (v" + versionStr + ")");
|
System.out.println(":: easy-es :: (v:" + versionStr + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
AnnotationAttributes mapperScanAttrs = AnnotationAttributes
|
AnnotationAttributes mapperScanAttrs = AnnotationAttributes
|
||||||
|
|||||||
@ -0,0 +1,55 @@
|
|||||||
|
package cn.easyes.common.utils;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.elasticsearch.client.RequestOptions;
|
||||||
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
|
import org.elasticsearch.client.core.MainResponse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ee 版本工具类
|
||||||
|
*
|
||||||
|
* @author dys
|
||||||
|
* @since 0.9.80
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
public class EEVersionUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定类版本号
|
||||||
|
* <ul>
|
||||||
|
* <li>只能获取jar包版本,并且打包后META-INF/MANIFEST.MF文件中存在 Implementation-Version</li>
|
||||||
|
* <li>不存在 Implementation-Version 时返回 unknown</li>
|
||||||
|
* <li>如果获取EE本身版本需要打包后获取,在test包测试用例中无法获取</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param objectClass T.getClass()
|
||||||
|
* @return classVersion
|
||||||
|
*/
|
||||||
|
public static <T> String getJarVersion(Class<T> objectClass) {
|
||||||
|
return Optional.ofNullable(objectClass.getPackage().getImplementationVersion()).
|
||||||
|
orElse("unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取elasticsearch client 版本
|
||||||
|
* <p>
|
||||||
|
* elasticsearch 客户端必须通过 restHighLevelClient.info 获取,无法使用getPackage.getImplementationVersion 获取
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param restHighLevelClient es高级客户端
|
||||||
|
* @return client version
|
||||||
|
*/
|
||||||
|
public static String getClientVersion(RestHighLevelClient restHighLevelClient) {
|
||||||
|
MainResponse info;
|
||||||
|
try {
|
||||||
|
info = restHighLevelClient.info(RequestOptions.DEFAULT);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return info.getVersion().getNumber();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,74 +0,0 @@
|
|||||||
package cn.easyes.common.utils;
|
|
||||||
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import org.elasticsearch.client.RequestOptions;
|
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
|
||||||
import org.elasticsearch.client.core.MainResponse;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* elasticsearch 版本工具类
|
|
||||||
*/
|
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
|
||||||
public class EsVersionUtil {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 支持的版本 目前支持版本为7.xx 推荐7.14.0
|
|
||||||
*/
|
|
||||||
private final static String supportedVersion = "7";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取es jar包版本
|
|
||||||
*
|
|
||||||
* @param restHighLevelClient es 高级客户端
|
|
||||||
* @return jar version
|
|
||||||
*/
|
|
||||||
public static String getJarVersion(RestHighLevelClient restHighLevelClient) {
|
|
||||||
String version = restHighLevelClient.getClass().getPackage().getImplementationVersion();
|
|
||||||
LogUtils.formatInfo("Elasticsearch jar version:%s", version);
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取elasticsearch client 版本
|
|
||||||
*
|
|
||||||
* @param restHighLevelClient es高级客户端
|
|
||||||
* @return client version
|
|
||||||
*/
|
|
||||||
public static String getClientVersion(RestHighLevelClient restHighLevelClient) {
|
|
||||||
MainResponse info;
|
|
||||||
try {
|
|
||||||
info = restHighLevelClient.info(RequestOptions.DEFAULT);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
String version = info.getVersion().getNumber();
|
|
||||||
LogUtils.formatInfo("Elasticsearch client version:%s", version);
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验es client版本及jar包版本
|
|
||||||
*
|
|
||||||
* @param restHighLevelClient es高级客户端
|
|
||||||
*/
|
|
||||||
public static void verify(RestHighLevelClient restHighLevelClient) {
|
|
||||||
// 校验jar包版本是否为推荐使用版本
|
|
||||||
String jarVersion = getJarVersion(restHighLevelClient);
|
|
||||||
if (!jarVersion.startsWith(supportedVersion)) {
|
|
||||||
// 这里抛出异常原因是ee强制依赖于jar包版本,jar包版本不对会导致ee异常
|
|
||||||
throw ExceptionUtils.eee("Easy-Es supported elasticsearch jar version is:%s.xx", supportedVersion);
|
|
||||||
}
|
|
||||||
String clientVersion = getClientVersion(restHighLevelClient);
|
|
||||||
if (!clientVersion.startsWith(supportedVersion)) {
|
|
||||||
// 这里校验客户端为非强制,客户端版本非推荐版本对应提醒即可,es会报错提醒
|
|
||||||
LogUtils.formatWarn("Easy-Es supported elasticsearch client version is:%s.xx", supportedVersion);
|
|
||||||
}
|
|
||||||
if (!jarVersion.equals(clientVersion)) {
|
|
||||||
// 提示jar包与客户端版本不对应,es官方推荐jar包版本对应客户端版本
|
|
||||||
LogUtils.formatWarn("Elasticsearch clientVersion:%s not equals jarVersion:%s", clientVersion, jarVersion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -10,6 +10,10 @@ import org.elasticsearch.client.RestHighLevelClient;
|
|||||||
*/
|
*/
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class RestHighLevelClientBuilder {
|
public class RestHighLevelClientBuilder {
|
||||||
|
/**
|
||||||
|
* 支持的版本 目前支持版本为7.xx 推荐7.14.0
|
||||||
|
*/
|
||||||
|
private final static String supportedVersion = "7";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建RestHighLevelClient
|
* 构建RestHighLevelClient
|
||||||
@ -20,8 +24,32 @@ public class RestHighLevelClientBuilder {
|
|||||||
public static RestHighLevelClient build(RestClientBuilder builder) {
|
public static RestHighLevelClient build(RestClientBuilder builder) {
|
||||||
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);
|
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);
|
||||||
// 检验es版本是否对应
|
// 检验es版本是否对应
|
||||||
EsVersionUtil.verify(restHighLevelClient);
|
verify(restHighLevelClient);
|
||||||
return restHighLevelClient;
|
return restHighLevelClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验es client版本及jar包版本
|
||||||
|
*
|
||||||
|
* @param restHighLevelClient es高级客户端
|
||||||
|
*/
|
||||||
|
private static void verify(RestHighLevelClient restHighLevelClient) {
|
||||||
|
// 校验jar包版本是否为推荐使用版本
|
||||||
|
String jarVersion = EEVersionUtil.getJarVersion(restHighLevelClient.getClass());
|
||||||
|
LogUtils.formatInfo("Elasticsearch jar version:%s", jarVersion);
|
||||||
|
if (!jarVersion.startsWith(supportedVersion)) {
|
||||||
|
// 这里抛出异常原因是ee强制依赖于jar包版本,jar包版本不对会导致ee异常
|
||||||
|
throw ExceptionUtils.eee("Easy-Es supported elasticsearch jar version is:%s.xx", supportedVersion);
|
||||||
|
}
|
||||||
|
String clientVersion = EEVersionUtil.getClientVersion(restHighLevelClient);
|
||||||
|
LogUtils.formatInfo("Elasticsearch client version:%s", clientVersion);
|
||||||
|
if (!clientVersion.startsWith(supportedVersion)) {
|
||||||
|
// 这里校验客户端为非强制,客户端版本非推荐版本对应提醒即可,es会报错提醒
|
||||||
|
LogUtils.formatWarn("Easy-Es supported elasticsearch client version is:%s.xx", supportedVersion);
|
||||||
|
}
|
||||||
|
if (!jarVersion.equals(clientVersion)) {
|
||||||
|
// 提示jar包与客户端版本不对应,es官方推荐jar包版本对应客户端版本
|
||||||
|
LogUtils.formatWarn("Elasticsearch clientVersion:%s not equals jarVersion:%s", clientVersion, jarVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,6 +35,7 @@
|
|||||||
<fastjson.version>1.2.83</fastjson.version>
|
<fastjson.version>1.2.83</fastjson.version>
|
||||||
<codec.version>1.13</codec.version>
|
<codec.version>1.13</codec.version>
|
||||||
<spring-boot.version>2.6.10</spring-boot.version>
|
<spring-boot.version>2.6.10</spring-boot.version>
|
||||||
|
<maven-jar-plugin.version>3.2.2</maven-jar-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@ -202,6 +203,20 @@
|
|||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<!--java getImplementationVersion获取版本号-->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>${maven-jar-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<!-- 【注】snapshotRepository 与 repository 中的 id 一定要与 setting.xml 中 server 的 id 保持一致! -->
|
<!-- 【注】snapshotRepository 与 repository 中的 id 一定要与 setting.xml 中 server 的 id 保持一致! -->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user