Apache Ignite配置错误

时间:2017-09-04 05:53:34

标签: ignite

我们已经构建了一个4节点Apache Ignite Cluster,并且可以进行连接并执行基本操作,例如从Java程序创建Cache。

但是当我进行MySQL集成时,它无法连接到Ignite集群。

以下是错误消息。

Exception in thread "main" class org.apache.ignite.IgniteException: Resource field is not assignable from the resource: class org.springframework.jdbc.datasource.DriverManagerDataSource
    at org.apache.ignite.internal.util.IgniteUtils.convertException(IgniteUtils.java:906)
    at org.apache.ignite.Ignition.start(Ignition.java:350)
    at PersonExample.PersonStoreExample.main(PersonStoreExample.java:16)
Caused by: class org.apache.ignite.IgniteCheckedException: Resource field is not assignable from the resource: class org.springframework.jdbc.datasource.DriverManagerDataSource
    at org.apache.ignite.internal.processors.resource.GridResourceUtils.inject(GridResourceUtils.java:50)
    at org.apache.ignite.internal.processors.resource.GridResourceSpringBeanInjector.inject(GridResourceSpringBeanInjector.java:67)
    at org.apache.ignite.internal.processors.resource.GridResourceIoc.injectInternal(GridResourceIoc.java:172)
    at org.apache.ignite.internal.processors.resource.GridResourceIoc.inject(GridResourceIoc.java:97)
    at org.apache.ignite.internal.processors.resource.GridResourceProcessor.injectGeneric(GridResourceProcessor.java:257)
    at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepare(GridCacheProcessor.java:539)
    at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepare(GridCacheProcessor.java:528)
    at org.apache.ignite.internal.processors.cache.GridCacheProcessor.createCache(GridCacheProcessor.java:1270)
    at org.apache.ignite.internal.processors.cache.GridCacheProcessor.onKernalStart(GridCacheProcessor.java:784)
    at org.apache.ignite.internal.IgniteKernal.start(IgniteKernal.java:926)
    at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start0(IgnitionEx.java:1736)
    at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start(IgnitionEx.java:1589)
    at org.apache.ignite.internal.IgnitionEx.start0(IgnitionEx.java:1042)
    at org.apache.ignite.internal.IgnitionEx.startConfigurations(IgnitionEx.java:964)
    at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:850)
    at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:749)
    at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:619)
    at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:589)
    at org.apache.ignite.Ignition.start(Ignition.java:347)
    ... 1 more

以下是Ignite配置文件:

<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">
   <!--
        Alter configuration below as needed.
    -->
   <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" name="dataSource">
      <property name="driverClassName" value="com.mysql.jdbc.Driver" />
      <property name="url" value="jdbc:mysql://<<mysqk_host>>:3306/sample_db" />
      <property name="username" value="root" />
      <property name="password" value="hadoop" />
   </bean>
   <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
      <property name="cacheConfiguration">
         <list>
            <bean class="org.apache.ignite.configuration.CacheConfiguration">
               <property name="name" value="personCache" />
               <property name="readThrough" value="true" />
               <property name="writeThrough" value="true" />
               <property name="cacheStoreFactory">
                  <bean class="javax.cache.configuration.FactoryBuilder" factory-method="factoryOf">
                     <constructor-arg value="PersonExample.PersonStore" />
                  </bean>
               </property>
               <property name="queryEntities">
                  <list>
                     <bean class="org.apache.ignite.cache.QueryEntity">
                        <property name="keyType" value="java.lang.Long" />
                        <property name="valueType" value="PersonExample.Person" />
                        <property name="fields">
                           <map>
                              <entry key="id" value="java.lang.Long" />
                              <entry key="name" value="java.lang.String" />
                              <entry key="orgId" value="java.lang.Long" />
                              <entry key="salary" value="java.lang.Integer" />
                           </map>
                        </property>
                     </bean>
                  </list>
               </property>
            </bean>
         </list>
      </property>
      <!--            <property name="peerClassLoadingEnabled" value="true"></property> -->
      <property name="discoverySpi">
         <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
            <property name="ipFinder">
               <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.zk.TcpDiscoveryZookeeperIpFinder">
                  <property name="zkConnectionString" value=“<<zk_host>>:2181" />
               </bean>
            </property>
         </bean>
      </property>
   </bean>

如何解决此错误?

1 个答案:

答案 0 :(得分:1)

错误已通过以下更改解决:

  • 在点燃Libs目录中添加了最新的MySQL JDBC jar
  • 确保群集配置文件和客户端配置文件相同(早期客户端配置文件在缓存配置中包含很少的其他配置)。
  • 添加了Person类(这是一个MySQL表POJO,将存储在Ignite缓存中)。