微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Spring-Boost 应用程序和 Apache Ignite 配置:启动 ApplicationContext 时出现问题

如何解决Spring-Boost 应用程序和 Apache Ignite 配置:启动 ApplicationContext 时出现问题

我正在尝试将 IgniteConfiguration 注入到这样的组件中:

import org.apache.ignite.IgniteException;
import org.apache.ignite.configuration.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ImportResource;
import org.springframework.stereotype.Component;

@Component
@ImportResource("classpath:default-config.xml")
public class DefaultConfigurations implements IConfigurations {

    @SuppressWarnings("unused")
    private static final Logger logger = LogManager.getLogger();
    @Autowired
    private IgniteConfiguration ignite_config;

    @Override
    public IgniteConfiguration getIgniteConfiguration() throws IgniteException {
        return ignite_config;
    }
}

资源 default-config.xml 包含 Apache Ignite 配置。

只要我使用以下 default-config.xml 一切正常:

<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License,Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,software
distributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
   http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
    <property name="workdirectory" value="E:\AVL\eclipse_workspace\dataservice\ignite_working_dir" />

    <!-- test configuration -->
    <property name="cacheConfiguration">
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
            <!-- Set the cache name. -->
            <property name="name" value="testCache" />
            <!-- Set the cache mode. -->
            <property name="cacheMode" value="LOCAL" />
            <!-- Other cache parameters. -->
        </bean>
    </property>

    <!--
    <property name="dataStorageConfiguration">
        <bean class="org.apache.ignite.configuration.DataStorageConfiguration">
            <property name="defaultDataRegionConfiguration">
                <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
                    <property name="name" value="default_data_region" />
                    <property name="initialSize" value="#{1L * 1024 * 1024 * 1024}" />
                    <property name="maxSize" value="#{10L *1024 * 1024 * 1024}" />
                </bean>
            </property>
        </bean>
    </property>
    -->
    
    </bean>
</beans>

但是当我取消注释 dataStorageConfiguration 属性时,我收到一个错误

Error starting ApplicationContext.

...

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.ignite.configuration.DataStorageConfiguration#38875e7d' defined in class path resource [default-config.xml]: Instantiation of bean Failed; nested exception is java.lang.ExceptionInInitializerError
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.instantiateBean(AbstractAutowireCapablebeanfactory.java:1316) ~[spring-beans-5.3.8.jar:5.3.8]
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.createBeanInstance(AbstractAutowireCapablebeanfactory.java:1214) ~[spring-beans-5.3.8.jar:5.3.8]
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.doCreateBean(AbstractAutowireCapablebeanfactory.java:564) ~[spring-beans-5.3.8.jar:5.3.8]
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.createBean(AbstractAutowireCapablebeanfactory.java:524) ~[spring-beans-5.3.8.jar:5.3.8]
    at org.springframework.beans.factory.support.BeanDeFinitionValueResolver.resolveInnerBean(BeanDeFinitionValueResolver.java:374) ~[spring-beans-5.3.8.jar:5.3.8]
    ... 46 common frames omitted
Caused by: java.lang.ExceptionInInitializerError: null
    at org.apache.ignite.internal.util.IgniteUtils.<clinit>(IgniteUtils.java:850) ~[ignite-core-2.10.0.jar:2.10.0]
    at org.apache.ignite.configuration.DataStorageConfiguration.<clinit>(DataStorageConfiguration.java:86) ~[ignite-core-2.10.0.jar:2.10.0]
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[na:na]
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[na:na]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:212) ~[spring-beans-5.3.8.jar:5.3.8]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) ~[spring-beans-5.3.8.jar:5.3.8]
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.instantiateBean(AbstractAutowireCapablebeanfactory.java:1308) ~[spring-beans-5.3.8.jar:5.3.8]
    ... 50 common frames omitted
Caused by: java.lang.RuntimeException: java.nio.DirectByteBuffer.address field is unavailable.
    at org.apache.ignite.internal.util.GridUnsafe$2.run(GridUnsafe.java:1567) ~[ignite-core-2.10.0.jar:2.10.0]
    at org.apache.ignite.internal.util.GridUnsafe$2.run(GridUnsafe.java:1554) ~[ignite-core-2.10.0.jar:2.10.0]
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:312) ~[na:na]
    at org.apache.ignite.internal.util.GridUnsafe.bufferAddressOffset(GridUnsafe.java:1554) ~[ignite-core-2.10.0.jar:2.10.0]
    at org.apache.ignite.internal.util.GridUnsafe.<clinit>(GridUnsafe.java:109) ~[ignite-core-2.10.0.jar:2.10.0]
    ... 60 common frames omitted
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field long java.nio.Buffer.address accessible: module java.base does not "opens java.nio" to unnamed module @29b5cd00
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357) ~[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:177) ~[na:na]
    at java.base/java.lang.reflect.Field.setAccessible(Field.java:171) ~[na:na]
    at org.apache.ignite.internal.util.GridUnsafe$2.run(GridUnsafe.java:1559) ~[ignite-core-2.10.0.jar:2.10.0]
    ... 64 common frames omitted

最奇怪的行为是: 当我从 Eclipse 运行应用程序时,两种配置都在工作。 :-)

我使用的是 AdoptOpenJDK 16。 这是启动脚本:

mvn spring-boot:run -f ..\pom.xml -Drun.arguments=--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED,--adDd-exports=java.base/sun.nio.ch=ALL-UNNAMED,--add-exports=java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED,--add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED,--add-exports=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED,--add-opens=jdk.managemednt/com.sun.management.internal=ALL-UNNAMED,--illegal-access=permit

我已将问题隔离到 JDK16。 使用 Java1.8 运行应用程序似乎工作正常......

有什么想法吗?

编辑: 切换到 AdoptOpenJDK-11 后,问题似乎消失了。 只弹出几个警告:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.ignite.internal.util.GridUnsafe$2 (file:/C:/Users/POSCHR/.m2/repository/org/apache/ignite/ignite-core/2.10.0/ignite-core-2.10.0.jar) to field java.nio.Buffer.address
WARNING: Please consider reporting this to the maintainers of org.apache.ignite.internal.util.GridUnsafe$2
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

@alamar 谢谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?