叫我杨哥5240 2022-01-11 20:08
浏览 317
已结题

关于elasticsearch存入自定义类报错,如何解决?(语言-java)

今天虚拟机安装了es6.8.10版本,想要springboot操作es测试一下,结果遇到了无法启动项目的情况
  Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.math.BigInteger java.math.BigDecimal.intVal accessible: module java.base does not "opens java.math" to unnamed module @38d8f54a
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[na:na]
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[na:na]
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178) ~[na:na]
at java.base/java.lang.reflect.Field.setAccessible(Field.java:172) ~[na:na]
at org.springframework.util.ReflectionUtils.makeAccessible(ReflectionUtils.java:782) ~[spring-core-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:500) ~[spring-data-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:705) ~[spring-core-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:374) ~[spring-data-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
at java.base/java.util.Collections$SingletonSet.forEach(Collections.java:4905) ~[na:na]
at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:548) ~[spring-data-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:506) ~[spring-data-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:705) ~[spring-core-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:374) ~[spring-data-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:248) ~[spring-data-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:191) ~[spring-data-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:85) ~[spring-data-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$4(RepositoryFactoryBeanSupport.java:295) ~[spring-data-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
at java.base/java.util.Optional.ifPresent(Optional.java:178) ~[na:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:295) ~[spring-data-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
at org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactoryBean.afterPropertiesSet(ElasticsearchRepositoryFactoryBean.java:67) ~[spring-data-elasticsearch-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
... 43 common frames omitted
大致看了一下,我认为是自定义类当中bigdecmal类型的问题,说是不能编译私有最终类Bigdecmal什么的

java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.math.BigInteger java.math.BigDecimal.intVal accessible: module java.base does not "opens java.math" to unnamed module @38d8f54a

自定义类:

public class ESGoods{
    private static final long serialVersionUID = 8509683142547327975L;

    /**
     * 商品id列
     */
    @Id
    private Long id;

    /**
     * 商品名称
     */
    @Field(type = FieldType.Text, analyzer = "ik_smart", searchAnalyzer = "ik_smart")
    private String goodsName;
    /**
     * 分类名称
     */
    @Field(type = FieldType.Keyword)
    private String spuName;
    /**
     * 商品品牌名称
     */
    @Field(type = FieldType.Keyword)
    private String goodsBrandName;
    /**
     * 商品价格
     */
    @Field(type = FieldType.Double)
    private BigDecimal amount;
    /**
     * 商品描述
     */
    @Field(type = FieldType.Text, analyzer = "ik_smart", searchAnalyzer = "ik_smart")
    private String description;
}

( 因为我用的是jdk17,第一次使用,也不知道是不是跟jdk版本有关 )

######我尝试将字段类型改为Double再运行了一下


/**
     * 商品价格
     */
    @Field(type = FieldType.Double)
    private Double amount;
启动成功

2022-01-11 20:03:52.129 INFO  [shop-elasticsearch] [traceId:][spanId:][parentSpanId:] --- [main] - [org.springframework.boot.SpringApplication:logStartupProfileInfo: 655] - The following profiles are active: dev
2022-01-11 20:03:53.421 INFO  [shop-elasticsearch] [traceId:][spanId:][parentSpanId:] --- [main] - [org.apache.juli.logging.DirectJDKLog:log: 173] - Starting service [Tomcat]
2022-01-11 20:03:53.421 INFO  [shop-elasticsearch] [traceId:][spanId:][parentSpanId:] --- [main] - [org.apache.juli.logging.DirectJDKLog:log: 173] - Starting Servlet engine: [Apache Tomcat/9.0.37]
2022-01-11 20:03:53.528 INFO  [shop-elasticsearch] [traceId:][spanId:][parentSpanId:] --- [main] - [org.apache.juli.logging.DirectJDKLog:log: 173] - Initializing Spring embedded WebApplicationContext
2022-01-11 20:03:54.444 WARN  [shop-elasticsearch] [traceId:][spanId:][parentSpanId:] --- [I/O dispatcher 1] - [org.elasticsearch.client.RequestLogger:logResponse: 65] - request [PUT http://192.168.153.129:9200/es_goods/_mapping/esgoods?master_timeout=30s&include_type_name=true&timeout=30s] returned 1 warnings: [299 Elasticsearch-6.8.10-537cb22 "[types removal] Specifying types in put mapping requests is deprecated. To be compatible with 7.0, the mapping definition should not be nested under the type name, and the parameter include_type_name must be provided and set to false."]
2022-01-11 20:03:54.586 INFO  [shop-elasticsearch] [traceId:][spanId:][parentSpanId:] --- [main] - [com.netflix.config.sources.URLConfigurationSource:<init>: 126] - URLs to be used as dynamic configuration source: [file:/E:/ideajavaproject/spring-cloud-shop/shop-elasticsearch/shop-elasticsearch-api/target/classes/config.properties]
2022-01-11 20:03:54.590 INFO  [shop-elasticsearch] [traceId:][spanId:][parentSpanId:] --- [main] - [com.netflix.config.sources.URLConfigurationSource:<init>: 126] - URLs to be used as dynamic configuration source: [file:/E:/ideajavaproject/spring-cloud-shop/shop-elasticsearch/shop-elasticsearch-api/target/classes/config.properties]
2022-01-11 20:03:55.919 INFO  [shop-elasticsearch] [traceId:][spanId:][parentSpanId:] --- [main] - [org.springframework.boot.StartupInfoLogger:logStarted: 61] - Started Elasticsearch in 4.99 seconds (JVM running for 6.032)
2022-01-11 20:03:56.026 INFO  [shop-elasticsearch] [traceId:][spanId:][parentSpanId:] --- [RMI TCP Connection(2)-192.168.153.1] - [org.apache.juli.logging.DirectJDKLog:log: 173] - Initializing Spring DispatcherServlet 'dispatcherServlet'



想请教知道的大lao解析一下是为何,越详细越好,感激不尽!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 1月19日
    • 创建了问题 1月11日

    悬赏问题

    • ¥30 STM32 INMP441无法读取数据
    • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
    • ¥15 用visualstudio2022创建vue项目后无法启动
    • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
    • ¥500 把面具戴到人脸上,请大家贡献智慧
    • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
    • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
    • ¥30 c#打开word开启修订并实时显示批注
    • ¥15 如何解决ldsc的这条报错/index error
    • ¥15 VS2022+WDK驱动开发环境