You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Zhengqingzheng <zh...@huawei.com> on 2016/07/19 09:29:07 UTC

ignite Spring application context resource is not injected problem

Hi there,
When I start Ignite client side code, I met the following error:
[17:13:37,062][SEVERE][exchange-worker-#38%default%][GridCachePartitionExchangeManager] Failed to wait for completion of partition map exchange (preloading will not start): GridDhtPartitionsExchangeFuture [dummy=false, forcePreload=false, reassign=false, discoEvt=DiscoveryCustomEvent [customMsg=DynamicCacheChangeBatch [reqs=[DynamicCacheChangeRequest [deploymentId=f8887010651-a952654b-c910-4516-b293-c2de7c1d5a4a, startCfg=CacheConfiguration [name=UniquefieldsCache, storeConcurrentLoadAllThreshold=5, rebalancePoolSize=2, rebalanceTimeout=10000, evictPlc=null, evictSync=false, evictKeyBufSize=1024, evictSyncConcurrencyLvl=4, evictSyncTimeout=10000, evictFilter=null, evictMaxOverflowRatio=10.0, eagerTtl=true, dfltLockTimeout=0, startSize=1500000, nearCfg=null, writeSync=PRIMARY_SYNC, storeFactory=CacheJdbcPojoStoreFactory [batchSizw=512, dataSrcBean=dataSource, dialect=o.a.i.cache.store.jdbc.dialect.OracleDialect@c1fe7e, maxPoolSize=12, maxWriteAttempts=2, parallelLoadCacheMinThreshold=512, hasher=o.a.i.cache.store.jdbc.JdbcTypeDefaultHasher@d8f790, dataSrc=null], storeKeepBinary=false, loadPrevVal=false, aff=o.a.i.cache.affinity.rendezvous.RendezvousAffinityFunction@d5ca86, cacheMode=PARTITIONED, atomicityMode=ATOMIC, atomicWriteOrderMode=PRIMARY, backups=0, invalidate=false, tmLookupClsName=null, rebalanceMode=ASYNC, rebalanceOrder=0, rebalanceBatchSize=524288, rebalanceBatchesPrefetchCount=2, offHeapMaxMem=-1, swapEnabled=false, maxConcurrentAsyncOps=500, writeBehindEnabled=false, writeBehindFlushSize=10240, writeBehindFlushFreq=5000, writeBehindFlushThreadCnt=1, writeBehindBatchSize=512, memMode=ONHEAP_TIERED, affMapper=o.a.i.i.processors.cache.CacheDefaultBinaryAffinityKeyMapper@1f240b8, rebalanceDelay=0, rebalanceThrottle=0, interceptor=null, longQryWarnTimeout=3000, readFromBackup=true, nodeFilter=o.a.i.configuration.CacheConfiguration$IgniteAllNodesPredicate@d57bb6, sqlSchema=null, sqlEscapeAll=false, sqlOnheapRowCacheSize=10240, snapshotableIdx=false, cpOnRead=true, topValidator=null], cacheType=USER, initiatingNodeId=d54726b7-7f79-4124-a021-0cdaf15e57ec, nearCacheCfg=null, clientStartOnly=true, stop=false, close=false, failIfExists=false, template=false, exchangeNeeded=true, cacheFutTopVer=null, cacheName=UniquefieldsCache]], clientNodes=null, id=7b18e620651-bda369c9-4b44-40c8-80b2-36e40bf889d2, clientReconnect=false], affTopVer=AffinityTopologyVersion [topVer=36, minorTopVer=1], super=DiscoveryEvent [evtNode=TcpDiscoveryNode [id=d54726b7-7f79-4124-a021-0cdaf15e57ec, addrs=[0:0:0:0:0:0:0:1, 10.135.66.169, 127.0.0.1], sockAddrs=[NKGY2Z002066461.china.huawei.com/10.135.66.169:0, /0:0:0:0:0:0:0:1:0, /10.135.66.169:0, /127.0.0.1:0], discPort=0, order=36, intOrder=0, lastExchangeTime=1468919612929, loc=true, ver=1.5.0#20151229-sha1:f1f8cda2, isClient=true], topVer=36, nodeId8=d54726b7, msg=null, type=DISCOVERY_CUSTOM_EVT, tstamp=1468919617026]], rcvdIds=GridConcurrentHashSet [elements=[]], rmtIds=null, exchId=GridDhtPartitionExchangeId [topVer=AffinityTopologyVersion [topVer=36, minorTopVer=1], nodeId=d54726b7, evt=DISCOVERY_CUSTOM_EVT], init=true, ready=false, replied=false, added=true, initFut=GridFutureAdapter [resFlag=2, res=false, startTime=1468919617026, endTime=1468919617041, ignoreInterrupts=false, lsnr=null, state=DONE], topSnapshot=null, lastVer=null, partReleaseFut=null, skipPreload=false, clientOnlyExchange=false, initTs=1468919617026, oldest=c29edcbc-85b3-4a70-8b61-98a9283d72a9, oldestOrder=1, evtLatch=0, remaining=[], super=GridFutureAdapter [resFlag=1, res=class o.a.i.IgniteException: Spring application context resource is not injected., startTime=1468919617026, endTime=1468919617041, ignoreInterrupts=false, lsnr=null, state=DONE]]
class org.apache.ignite.IgniteCheckedException: Spring application context resource is not injected.
         at org.apache.ignite.internal.util.IgniteUtils.cast(IgniteUtils.java:7005)
         at org.apache.ignite.internal.util.future.GridFutureAdapter.get0(GridFutureAdapter.java:166)
         at org.apache.ignite.internal.util.future.GridFutureAdapter.get(GridFutureAdapter.java:115)
         at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body(GridCachePartitionExchangeManager.java:1299)
         at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110)
         at java.lang.Thread.run(Thread.java:745)
Caused by: class org.apache.ignite.IgniteException: Spring application context resource is not injected.
         at org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory.create(CacheJdbcPojoStoreFactory.java:156)
         at org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory.create(CacheJdbcPojoStoreFactory.java:96)
         at org.apache.ignite.internal.processors.cache.GridCacheProcessor.createCache(GridCacheProcessor.java:1243)
         at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareCacheStart(GridCacheProcessor.java:1638)
         at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareCachesStart(GridCacheProcessor.java:1563)
         at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.startCaches(GridDhtPartitionsExchangeFuture.java:956)
         at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.init(GridDhtPartitionsExchangeFuture.java:523)
         at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body(GridCachePartitionExchangeManager.java:1297)
         ... 2 more

When I checked the code inside the ignite(CacheJdbcPojoStoreFactory.java), I am confused with the following code:
  if (dataSrc != null)
            store.setDataSource(dataSrc);
        else {
            if (dataSrcBean != null) {
                if (appCtx == null)
                    throw new IgniteException("Spring application context resource is not injected.");

                IgniteSpringHelper spring;

                try {
                    spring = IgniteComponentType.SPRING.create(false);

                    DataSource data = spring.loadBeanFromAppContext(appCtx, dataSrcBean);

                    store.setDataSource(data);
                }
                catch (Exception e) {
                    throw new IgniteException("Failed to load bean in application context [beanName=" + dataSrcBean +
                        ", igniteConfig=" + appCtx + ']', e);
                }
            }
        }

I did not see anywhere the appCtx is initialized.
In my xml config file I have defined datasource bean as follows:
<!-- Sample data source -->
         <bean id= "dataSource" class="oracle.jdbc.pool.OracleDataSource">
         <property name="URL" value="jdbc:oracle:thin:@xxx.xxx.xxx.xx:1521:xxx"/>
         <property name="user" value="xxxx"/>
         <property name="password" value="xxxxxx"/>
         </bean>


and used in jdbcpojostorefactory declaration:
<bean class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory">
         <property name="dataSourceBean" value="dataSource"/>
<property name="dialect">
                   <bean class="org.apache.ignite.cache.store.jdbc.dialect.OracleDialect"/>
         </property>
         <property name="types">
                   <list>
                            <bean class="org.apache.ignite.cache.store.jdbc.JdbcType">
                   …..

Any help?


Best regards,
Kevin

答复: ignite Spring application context resource is not injected problem

Posted by Zhengqingzheng <zh...@huawei.com>.
Hi Val,
I tried both. And non of them work for me:
1. first I start from ignite.sh script, cache created okay. However, when I call from the client side (using Ignition.start()) to put data into cache, it gives me Spring application context resource is not injected error.
2. I restart the server without any cache configuration, and start to create the cache from the client side. And the same error occurred again.
Here is my 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:util="http://www.springframework.org/schema/util"
       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
                           http://www.springframework.org/schema/util
                           http://www.springframework.org/schema/util/spring-util.xsd">
    <!--
        Alter configuration below as needed.
    -->
	<!-- Sample data source -->
	<bean id= "dataSource" class="oracle.jdbc.pool.OracleDataSource">
	 <property name="URL" value="jdbc:oracle:thin:@xxx.xxx.xx.xx:xxx:xxx"/>
	 <property name="user" value="xxxxx"/>
	 <property name="password" value="xxxxx"/>
	</bean>
	   
	<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
	    <!-- Enable client mdoe. -->
		<property name="clientMode" value="true"/>
		<property name="peerClassLoadingEnabled" value="false"/>
		
 		 <property name="cacheConfiguration">
		  <list>
			<!-- define uniquefields cache -->
			<bean class="org.apache.ignite.configuration.CacheConfiguration">
			
				<property name="readThrough" value="false"/>
				<property name="writeThrough" value="true"/>
				<property name="cacheMode" value="PARTITIONED"/>
				<property name="atomicityMode" value="ATOMIC"/>
				<property name="swapEnabled" value="false"/>
				<property name="name" value="UniquefieldsCache"/>
				<property name="cacheStoreFactory">
				
					<bean class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory">
						<property name="dataSourceBean" value="dataSource"/>
						<property name="dialect">
							<bean class="org.apache.ignite.cache.store.jdbc.dialect.OracleDialect"/>
						</property>
	
						<property name="types"> 
							<list> 
								<bean class="org.apache.ignite.cache.store.jdbc.JdbcType">
									<property name="databaseSchema" value="DEQUATIONS"/>
									<property name="databaseTable" value="UNIQUEFIELDS"/>
									<property name="keyType" value="com.huawei.soa.ignite.model.UniquefieldsKey"/>
									<property name="valueType" value="com.huawei.soa.ignite.model.Uniquefields"/>
									<property name="keyFields">
										<list>
											<bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
												<property name="databaseFieldType">
													<util:constant static-field="java.sql.Types.VARCHAR"/>
												</property>
												<property name="databaseFieldName" value="OBJID"/>
												<property name="javaFieldType" value="java.lang.String"/>
												<property name="javaFieldName" value="objid"/>
											</bean>
											<bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
												<property name="databaseFieldType">
													<util:constant static-field="java.sql.Types.VARCHAR"/>
												</property>
												<property name="databaseFieldName" value="STRINGVALUE"/>
												<property name="javaFieldType" value="java.lang.String"/>
												<property name="javaFieldName" value="stringvalue"/>
											</bean>
											<bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
												<property name="databaseFieldType">
													<util:constant static-field="java.sql.Types.NUMERIC"/>
												</property>
												<property name="databaseFieldName" value="NUMVALUE"/>
												<property name="javaFieldType" value="java.math.BigDecimal"/>
												<property name="javaFieldName" value="numvalue"/>
											</bean>
										</list>
									</property>
									<property name="valueFields">
										<list>
											<bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
												<property name="databaseFieldType">
													<util:constant static-field="java.sql.Types.VARCHAR"/>
												</property>
												<property name="databaseFieldName" value="ORGID"/>
												<property name="javaFieldType" value="java.lang.String"/>
												<property name="javaFieldName" value="orgid"/>
											</bean>
											<bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
												<property name="databaseFieldType">
													<util:constant static-field="java.sql.Types.VARCHAR"/>
												</property>
												<property name="databaseFieldName" value="OBJID"/>
												<property name="javaFieldType" value="java.lang.String"/>
												<property name="javaFieldName" value="objid"/>
											</bean>
											<bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
												<property name="databaseFieldType">
													<util:constant static-field="java.sql.Types.SMALLINT"/>
												</property>
												<property name="databaseFieldName" value="FIELDNUM"/>
												<property name="javaFieldType" value="java.lang.Short"/>
												<property name="javaFieldName" value="fieldnum"/>
											</bean>
											<bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
												<property name="databaseFieldType">
													<util:constant static-field="java.sql.Types.VARCHAR"/>
												</property>
												<property name="databaseFieldName" value="GUID"/>
												<property name="javaFieldType" value="java.lang.String"/>
												<property name="javaFieldName" value="guid"/>
											</bean>
											<bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
												<property name="databaseFieldType">
													<util:constant static-field="java.sql.Types.VARCHAR"/>
												</property>
												<property name="databaseFieldName" value="STRINGVALUE"/>
												<property name="javaFieldType" value="java.lang.String"/>
												<property name="javaFieldName" value="stringvalue"/>
											</bean>
											<bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
												<property name="databaseFieldType">
													<util:constant static-field="java.sql.Types.NUMERIC"/>
												</property>
												<property name="databaseFieldName" value="NUMVALUE"/>
												<property name="javaFieldType" value="java.math.BigDecimal"/>
												<property name="javaFieldName" value="numvalue"/>
											</bean>
											<bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
												<property name="databaseFieldType">
													<util:constant static-field="java.sql.Types.DATE"/>
												</property>
												<property name="databaseFieldName" value="DATEVALUE"/>
												<property name="javaFieldType" value="java.sql.Timestamp"/>
												<property name="javaFieldName" value="datevalue"/>
											</bean>
										</list>
									</property>
								</bean>
								
								
							</list>
						</property>
					</bean>
				</property>
				
				<property name="queryEntities">
					<list>
						<bean class="org.apache.ignite.cache.QueryEntity">
							<property name="keyType" value="com.huawei.soa.ignite.model.UniquefieldsKey"/>
							<property name="valueType" value="com.huawei.soa.ignite.model.Uniquefields"/>
							<property name="fields">
								<util:map map-class="java.util.LinkedHashMap">
									<entry key="orgid" value="java.lang.String"/>
									<entry key="objid" value="java.lang.String"/>
									<entry key="fieldnum" value="java.lang.Short"/>
									<entry key="guid" value="java.lang.String"/>
									<entry key="stringvalue" value="java.lang.String"/>
									<entry key="numvalue" value="java.math.BigDecimal"/>
									<entry key="datevalue" value="java.sql.Timestamp"/>
								</util:map>
							</property>
						</bean>
					
					</list>
				</property>
			</bean>
		
		  </list>
		 </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.vm.TcpDiscoveryVmIpFinder">
				  <property name="addresses">
					<list>
						<value>xxx.xxx.xxx.xxx:47500..47509</value>
	
					</list>
				  </property>
				</bean>
			  </property>
			</bean>
		</property> 
	</bean>
</beans>

Best regards,
Kevin

----------------------------------------------------------
-----邮件原件-----
发件人: vkulichenko [mailto:valentin.kulichenko@gmail.com] 
发送时间: 2016年7月20日 7:36
收件人: user@ignite.apache.org
主题: Re: ignite Spring application context resource is not injected problem

Hi Kevin,

Can you please provide the whole configuration file and also show how you start the node? Is it a standalone node started with ignite.sh script or an embedded node started in code using Ignition.start()?

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/ignite-Spring-application-context-resource-is-not-injected-problem-tp6377p6397.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: 答复: ignite Spring application context resource is not injected problem

Posted by vkulichenko <va...@gmail.com>.
Kevin,

This exception is thrown if Ignite node was started without knowing about
the Spring app context. Generally it works if it is started using
Ignition.start(..) method which gets a Spring configuration file, or if
default Ignition.start() is used. The latter looks like your case, so I
don't understand why it doesn't work for you.

Can you provide the exact piece of code that started the node? Or maybe you
have the test that I can run to reproduce the issue?
Also do you use any Spring integration classes like SpringCacheManager or
IgniteSpringBean?

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/ignite-Spring-application-context-resource-is-not-injected-problem-tp6377p6403.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

答复: ignite Spring application context resource is not injected problem

Posted by Zhengqingzheng <zh...@huawei.com>.
Hi Val,

Problem solved by using new class to extends from CacheJdbcPojoStoreFactory to solve this problem. But I think ignite should consider why the default CacheJdbcPojoStoreFactory not work, there might be a bug, because using default  CacheJdbcPojoStoreFactory even with datasource bean defined not work.

In my case, change the cachejdbcpojostorefactory bean class under cacheconfiguration bean to an self defined class which is extend from CacheJdbcPojoStoreFactory, with data source added inside the create metehod.
For example:
Change :
<property name="cacheStoreFactory">
			<bean class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory"> 
			....
To

<property name="cacheStoreFactory">
				
					<bean class="this.is.package.CacheJdbcPojoStoreExampleFactory">

Where inside the CacheJdbcPojoStoreExampleFactory  implement create method like this:

//创建 oracle data source 对象
        OracleDataSource oracleDataSource;
        try
        {
            oracleDataSource = new OracleDataSource();
            oracleDataSource.setURL(IgniteMetaUtils.NEW_DB_ADDR);
            oracleDataSource.setUser(IgniteMetaUtils.NEW_USER);
            oracleDataSource.setPassword(IgniteMetaUtils.NEW_PASS);
 
            //设定data source
            setDataSource(oracleDataSource);
        }
        catch (SQLException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

-----邮件原件-----
发件人: vkulichenko [mailto:valentin.kulichenko@gmail.com] 
发送时间: 2016年7月20日 7:36
收件人: user@ignite.apache.org
主题: Re: ignite Spring application context resource is not injected problem

Hi Kevin,

Can you please provide the whole configuration file and also show how you start the node? Is it a standalone node started with ignite.sh script or an embedded node started in code using Ignition.start()?

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/ignite-Spring-application-context-resource-is-not-injected-problem-tp6377p6397.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: ignite Spring application context resource is not injected problem

Posted by vkulichenko <va...@gmail.com>.
Hi Kevin,

Can you please provide the whole configuration file and also show how you
start the node? Is it a standalone node started with ignite.sh script or an
embedded node started in code using Ignition.start()?

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/ignite-Spring-application-context-resource-is-not-injected-problem-tp6377p6397.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.