spring - 使用 Spring Boot 和 Spring Data GemFire 连接 GemFire

标签 spring spring-boot spring-data gemfire geode

我正在尝试使用 Spring Data GemFire 和 Spring Boot 连接到现有的 GemFire 定位器。

以下是我的缓存配置

<?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>

当我尝试运行此代码时,出现以下异常

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

我的 POM 是

<?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>

主要应用如下: @SpringBootApplication 公共(public)类ContinousQueryClientApplication {

public static void main(String[] args) {
    new ClassPathXmlApplicationContext("client/cache-config.xml");
    SpringApplication.run(ContinousQueryClientApplication.class, args);
}

}

原因是什么,如何解决。

最佳答案

因此,当用户使用 Gfsh(未混合使用 Spring)启动 GemFire 服务器,然后尝试使用 Spring 配置的缓存客户端(特别是使用 <gfe:data-source>)连接到这些 GemFire 服务器时,通常会出现此问题。元素,它错误地假设 GemFire 服务器也是使用 Spring 配置和引导的。

我已经分离了SDG提供的必要的org.springframework.data.gemfire.support.ListRegionsOnServerFunction类成一个单独的JAR file可以在启动时添加到非 Spring 配置/启动的 GemFire 服务器的 CLASSPATH,或者使用 Gfsh 的“deploy”命令更方便。有关“部署”命令的更多详细信息,请参阅 here .

有关此问题的更多详细信息,请参阅... https://jira.spring.io/browse/SGF-409

希望这有帮助!

关于spring - 使用 Spring Boot 和 Spring Data GemFire 连接 GemFire,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29965092/

相关文章:

java - Spring Data Mongodb 存储库没有正确实现继承

spring - 导入org.springframework.hateoas.mvc无法解析

java - 带有 resteasy 的 Spring 启动 - "could not find the type for bean named requestMappingHandlerMapping"错误

java - Spring Repository @Async Future<List<T>> 返回错误类型

java - 如何在 Spring Boot 控制台应用程序中验证实体?

java - 如何在 Spring Boot 应用程序中读取和存储 apk 元数据

java - 如何正确使用ExtensionManager和ExtensionHandler实现类

Spring-Boot Embedded Tomcat - 生成localhost.log和cataline.out文件

java - 如何使用 xml 正确配置 Apache Camel 和 Spring JPA

java - Spring @SessionAttribute 如何在同一 Controller 中检索 session 对象