Spring Boot连接到数据透视云缓存



我的项目使用的是Spring Boot 2.0.4-RELEASE版本。我们正在Pivotal Cloud Foundry上进行部署,并使用使用Apache Geode的Pivotal云缓存服务。如果我使用gemfire shell创建云缓存区域,我的代码已经启动并运行,但我想从我的代码中创建这些区域,这样就不会遗漏任何内容。我有下面的配置类,我试图在其中创建一个区域

package com.mycompany.services.config;
import org.apache.geode.cache.ExpirationAction;
import org.apache.geode.cache.ExpirationAttributes;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.RegionShortcut;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
import org.springframework.data.gemfire.config.annotation.EnableCachingDefinedRegions;
import org.springframework.data.gemfire.config.annotation.EnablePdx;
@Configuration
@EnableCachingDefinedRegions
@EnablePdx()
public class Config {
@Bean
public PartitionedRegionFactoryBean<?, ?> createCacheRegion(GemFireCache gemfireCache) {
int expirationTime = 600;
String regionName = "cacheRegion";
PartitionedRegionFactoryBean<?, ?> newRegion = new PartitionedRegionFactoryBean<>();
newRegion.setCache(gemfireCache);
newRegion.setClose(false);
newRegion.setPersistent(true);
newRegion.setName(regionName);
ExpirationAttributes entryTimeToLive = new ExpirationAttributes(expirationTime,  ExpirationAction.INVALIDATE);
newRegion.setEntryTimeToLive(entryTimeToLive);
newRegion.setShortcut(RegionShortcut.REPLICATE);
return newRegion;
}
}

然而,当这段代码在Pivotal Cloud Foundry上运行时,我得到了以下错误

2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] 2018-11-08 17:46:09.795 ERROR 19 --- [ main] o.s.boot.SpringApplication : Application run failed
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dqsCacheRegion' defined in class path resource [com/mycompany/services/config/Config.class]: Invocation of init method failed; nested exception is java.lang.UnsupportedOperationException: operation is not supported on a client cache
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:740) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398) [spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]

有人能就我需要做什么来在我的代码中创建数据透视云缓存(Apache Geode(区域提供任何建议吗?而不是必须使用gemfire shell 来创建它们

谢谢Damien

客户端应用程序无法在服务器上创建区域,这项任务应由具有管理员权限的操作员通过gfsh、单个cache.xml配置文件或cluster configuration service执行。允许客户端任意创建区域可能会适得其反,并在集群中产生大量未使用的区域以及不必要的噪音和开销,这对于生产环境来说是完全不建议的。

也就是说,Spring Data for Apache Geode/GemFire允许您自动将配置从客户端应用程序推送到集群,这在开发环境中很有用。我不知道Pivotal云缓存内部策略和限制是否允许这样做,您可能想直接与Pivotal核实。

希望这能有所帮助。干杯

相关内容

  • 没有找到相关文章

最新更新