如何从spring配置文件启动ignite时读取application.properties文件

bz4sfanl  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(376)

我试图从spring配置xml文件启动apacheignite。springxml具有从application.properties文件读取的密钥。
我使用以下命令启动apacheignite

apache-ignite-fabric-2.6.0-bin\bin\ignite.bat D:\workspace\<application-name>\src\main\resources\ignite.xml

我试着设置一个classpath环境变量,其中保存了所有相关的spring和ignitejar,还保存了application.properties文件。现在仍然可以读取apploication.properties文件。

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'ignite.cfg' defined in URL [file:/D:/workspace/<application-name>/src/main/resources/ignite.xml]: No configuration setting found for key 'zookeeper'; nested exception is com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'zookeeper'
    at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:223)
    at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:222)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:86)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:283)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:163)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525)
    at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.applicationContext(IgniteSpringHelperImpl.java:381)

我尝试过设置类路径,也尝试过将文件/jar保存在ignite\u home目录的lib目录中。
ignite.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:util="http://www.springframework.org/schema/util"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util.xsd">

<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
    <!--<property name="gridLogger">
        <bean class="org.apache.ignite.logger.slf4j.Slf4jLogger"/>
    </property>-->

    <!-- Enabling Apache Ignite native persistence. -->
    <property name="peerClassLoadingEnabled" value="false"/>
    <property name="dataStorageConfiguration">
        <bean class="org.apache.ignite.configuration.DataStorageConfiguration">
            <property name="walMode" value="NONE"/>
            <property name="walArchivePath" value="D:\work\TIWorkspace\ignite\wal\archive"/>
            <property name="defaultDataRegionConfiguration">
                <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
                    <property name="persistenceEnabled" value="true"/>
                    <!-- Increasing the buffer size to 1 GB. -->
                    <property name="checkpointPageBufferSize"
                              value="#{1024L * 1024 * 1024}"/>
                </bean>
            </property>
        </bean>
    </property>
    <property name="binaryConfiguration">
        <bean class="org.apache.ignite.configuration.BinaryConfiguration">
            <property name="compactFooter" value="false"/>

            <property name="idMapper">
                <bean class="org.apache.ignite.binary.BinaryBasicIdMapper">
                    <property name="lowerCase" value="true"/>
                </bean>
            </property>

            <property name="nameMapper">
                <bean class="org.apache.ignite.binary.BinaryBasicNameMapper">
                    <property name="simpleName" value="true"/>
                </bean>
            </property>

        </bean>
    </property>

    <property name="discoverySpi">
        <bean class="org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi">
            <property name="zkConnectionString" value="localhost:2181"/>
            <!--<property name="zkConnectionString" value="${zookeeper.server}"/>-->
            <property name="zkRootPath" value="/dbobjects"/>
        </bean>
    </property>

</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>classpath:application.properties</value>
    </property>
</bean>

任何线索都有帮助。
提前谢谢。

c7rzv4ha

c7rzv4ha1#

实现这一点最直接的方法是使用基于文件的资源 URL . 这个对我有用:

<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="locations">
       <list>
           <value>file:${IGNITE_HOME}/libs/application.properties</value>
       </list>
   </property>
</bean>

相关问题