问题
I am trying to connect to an existing GemFire Locator using Spring Data GemFire and Spring Boot.
Following is my cache configuration
<?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:cache="http://www.springframework.org/schema/cache"
xmlns:gfe="http://www.springframework.org/schema/gemfire"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:gfe-data="http://www.springframework.org/schema/data/gemfire"
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/data/gemfire http://www.springframework.org/schema/data/gemfire/spring-data-gemfire.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<gfe-data:datasource subscription-enabled="true">
<gfe-data:locator host="192.168.1.44" port="5555" />
</gfe-data:datasource>
<gfe:cq-listener-container id="cqueryListener">
<gfe:listener ref="cqListener"
query="select * from /allSensors " />
</gfe:cq-listener-container>
<bean id="cqListener" class="cabigemfire.CQListener" />
</beans>
When I try to run this code I am getting the following exception
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.boot.maven.RunMojo$LaunchRunner.run(RunMojo.java:418)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.gemstone.gemfire.cache.client.ServerOperationException: : While performing a remote execute Functionorg.springframework.data.gemfire.support.ListRegionsOnServerFunction
at com.gemstone.gemfire.cache.client.internal.ExecuteFunctionOp$ExecuteFuncti onOpImpl.processResponse(ExecuteFunctionOp.java:623)
at com.gemstone.gemfire.cache.client.internal.AbstractOp.processResponse(AbstractOp.java:218)
at com.gemstone.gemfire.cache.client.internal.AbstractOp.attemptReadResponse( AbstractOp.java:153)
at com.gemstone.gemfire.cache.client.internal.AbstractOp.attempt(AbstractOp.java:372)
at com.gemstone.gemfire.cache.client.internal.ConnectionImpl.execute(ConnectionImpl.java:267)
at com.gemstone.gemfire.cache.client.internal.pooling.PooledConnection.execute(PooledConnection.java:320)
at com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.executeWithPossibleReAuthentication(OpExecutorImpl.java:942)
at com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.executeOnServer(OpExecutorImpl.java:375)
at com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.executeOn(OpExecutorImpl.java:339)
at com.gemstone.gemfire.cache.client.internal.PoolImpl.executeOn(PoolImpl.java:732)
at com.gemstone.gemfire.cache.client.internal.SingleHopOperationCallable.call(SingleHopOperationCallable.java:46)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java: 1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
... 1 more
Caused by: java.lang.ClassNotFoundException: org.springframework.data.gemfire.support.ListRegionsOnServerFunction
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:340)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:626)
at com.gemstone.gemfire.internal.InternalDataSerializer$DSObjectInputStream.resolveClass(InternalDataSerializer.java:3563)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1613)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at com.gemstone.gemfire.internal.InternalDataSerializer.basicReadObject(InternalDataSerializer.java:2966)
at com.gemstone.gemfire.DataSerializer.readObject(DataSerializer.java:3210)
at com.gemstone.gemfire.internal.util.BlobHelper.deserializeBlob(BlobHelper.java:110)
at com.gemstone.gemfire.internal.util.BlobHelper.deserializeBlob(BlobHelper.java:77)
at com.gemstone.gemfire.internal.cache.tier.sockets.CacheServerHelper.deserialize(CacheServerHelper.java:55)
at com.gemstone.gemfire.internal.cache.tier.sockets.Part.getObject(Part.java:233)
at com.gemstone.gemfire.internal.cache.tier.sockets.Part.getObject(Part.java:238)
at com.gemstone.gemfire.internal.cache.tier.sockets.Part.getStringOrObject(Part.java:243)
at com.gemstone.gemfire.internal.cache.tier.sockets.command.ExecuteFunction66.cmdExecute(ExecuteFunction66.java:124)
at com.gemstone.gemfire.internal.cache.tier.sockets.command.ExecuteFunction70.cmdExecute(ExecuteFunction70.java:51)
at com.gemstone.gemfire.internal.cache.tier.sockets.BaseCommand.execute(BaseCommand.java:182)
at com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection.doNormalMsg(ServerConnection.java:789)
at com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection.doOneMessage(ServerConnection.java:920)
at com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection.run(ServerConnection.java:1165)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at com.gemstone.gemfire.internal.cache.tier.sockets.AcceptorImpl$1$1.run(AcceptorImpl.java:577)
... 1 more
My POM is
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>in.demi</groupId>
<artifactId>GemFireDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>continousQueryClient</name>
<description>A CQ client for GemFire. </description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>cabigemfire.ContinousQueryClientApplication</start-class>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-gemfire</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>gemfire-repository</id>
<name>Gemfire Repository</name>
<url>http://dist.gemstone.com/maven/release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
The main application is as follows: @SpringBootApplication public class ContinousQueryClientApplication {
public static void main(String[] args) {
new ClassPathXmlApplicationContext("client/cache-config.xml");
SpringApplication.run(ContinousQueryClientApplication.class, args);
}
}
What is the cause and how can it be resolved.
回答1:
I would encourage you to create a JIRA issue for this https://jira.spring.io/browse/SGF. Meanwhile, try replacing gfe:datasource with gfe:client-cache and pool with subscriptions enabled. This will avoid calling ListRegionsOnServerFunction. Note that gfe:datasource is provided as a convenience and creates a client connection and a client region for each region discovered on the server via the remote function in question. CQ does not require a client region, so datasource is doing unnecessary work in this case, unless your application specifically requires a client region.
回答2:
So, this problem generally occurs when users start their GemFire Servers using Gfsh (with no Spring in the mix) and then subsequently try to connect to those GemFire Servers using a Spring-configured cache client, specifically with the <gfe:data-source>
element, which incorrectly assumes the GemFire Servers were configured and bootstrapped with Spring as well.
I have separated the necessary SDG-provided org.springframework.data.gemfire.support.ListRegionsOnServerFunction
class into a separate JAR file that can be added to a non-Spring configured/booted GemFire Server's CLASSPATH on start, or more conveniently with Gfsh's 'deploy' command. More details on the 'deploy' command are available here.
For more details on the issue, see... https://jira.spring.io/browse/SGF-409
Hope this helps!
来源:https://stackoverflow.com/questions/29965092/connecting-gemfire-using-spring-boot-and-spring-data-gemfire