有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java SpringBoost应用程序和Apache Ignite配置:启动ApplicationContext时出现问题

我正在尝试将Ignite配置注入如下组件:

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;
    }
}

资源默认配置。xml持有ApacheIgnite配置

只要我使用以下默认配置。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运行应用程序时,两种配置都在工作。 :-)

我正在使用OpenJDK 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似乎很好用

有什么想法吗

编辑: 切换到OpenJDK-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谢谢你


共 (0) 个答案