问题创建区域和将区域持久保存到磁盘Geode Gemfire Spring Boot

问题描述 投票:0回答:1

我观看了来自Springone Platform和John Blum的演讲者,并且有兴趣尝试在Geode / Gemfire设置中尝试自己的设置,但是设置如Spring Data for Apache Geode Reference Guide中所述]

因此,我使用Eclipse制作了Spring Boot Geode客户端,定位器和缓存服务器,并且在出现以下问题时遇到了问题:

  1. 启动spring locator,启动cache服务器,并使用restcontroller启动客户端,因此我可以发布POJO TitleContent并获取TitleContent列表。客户端给我例外原因:org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://localhost:7070/gemfire/v1/regions": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
  2. 完整日志:

2019-10-29 09:54:12.461 ERROR 58556 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Failed to start bean 'gemfireClusterSchemaObjectInitializer'; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://localhost:7070/gemfire/v1/regions": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:185) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:894) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at network.powerhouse.commercehost.CommerceHostGeodeApplication.main(CommerceHostGeodeApplication.java:51) [classes/:na]
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://localhost:7070/gemfire/v1/regions": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:751) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:644) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.data.gemfire.config.admin.remote.RestHttpGemfireAdminTemplate.createRegion(RestHttpGemfireAdminTemplate.java:267) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.data.gemfire.config.schema.definitions.RegionDefinition.create(RegionDefinition.java:125) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration$ClusterSchemaObjectInitializer.lambda$null$0(ClusterConfigurationConfiguration.java:403) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at java.base/java.util.Optional.ifPresent(Optional.java:172) ~[na:na]
    at org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration$ClusterSchemaObjectInitializer.lambda$start$1(ClusterConfigurationConfiguration.java:402) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) ~[na:na]
    at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357) ~[na:na]
    at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[na:na]
    at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[na:na]
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[na:na]
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]
    at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497) ~[na:na]
    at org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration$ClusterSchemaObjectInitializer.start(ClusterConfigurationConfiguration.java:402) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    ... 14 common frames omitted
Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]
    at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:400) ~[na:na]
    at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:243) ~[na:na]
    at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:225) ~[na:na]
    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:402) ~[na:na]
    at java.base/java.net.Socket.connect(Socket.java:591) ~[na:na]
    at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:657) ~[na:na]
    at java.base/sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:174) ~[na:na]
    at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:182) ~[na:na]
    at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474) ~[na:na]
    at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:569) ~[na:na]
    at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:265) ~[na:na]
    at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:372) ~[na:na]
    at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191) ~[na:na]
    at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1181) ~[na:na]
    at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1075) ~[na:na]
    at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177) ~[na:na]
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:163) ~[na:na]
    at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:76) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:742) ~[spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    ... 31 common frames omitted
  1. 我备注@EnableClusterConfiguration(useHttp = true)并再次启动Client,现在可以运行。现在,我尝试向我的restcontroller发送POJO帖子,并获得此异常:

2019-10-29 09:43:08.193错误57276-[io-15050-exec-1] oaccC [。[。[/]。[dispatcherServlet]:Servlet [dispatcherServlet]中的Servlet.service()路径[]的上下文引发异常[请求处理失败;嵌套的异常是org.springframework.dao.DataAccessResourceFailureException:远程服务器位于192.168.100.8(SpringBasedCacheClientApplication:57276:loner):64494:51246215:SpringBasedCacheClientApplication::执行远程放置时;嵌套的异常是org.apache.geode.cache.client.ServerOperationException:远程服务器位于192.168.100.8(SpringBasedCacheClientApplication:57276:loner):64494:51246215:SpringBasedCacheClientApplication::执行远程放置时]的根本原因

  • 这次我取消注释// @ EnableClusterConfiguration(useHttp = true),但是我删除了useHttp并仅使用@EnableClusterConfiguration,(我因此怀疑是错误的)。我停止Spring Client并重新启动。现在它失败了,并说:org.apache.geode.cache.RegionExistsException:/ TitleContent。
  • 完整日志:

    Application run failed org.springframework.context.ApplicationContextException: Failed to start bean 'gemfireClusterSchemaObjectInitializer'; nested exception is org.apache.geode.cache.execute.FunctionException: org.apache.geode.cache.RegionExistsException: /TitleContent at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:185) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:894) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] at network.powerhouse.commercehost.CommerceHostGeodeApplication.main(CommerceHostGeodeApplication.java:51) [classes/:na] Caused by: org.apache.geode.cache.execute.FunctionException: org.apache.geode.cache.RegionExistsException: /TitleContent at org.apache.geode.internal.cache.tier.sockets.command.ExecuteFunction66.cmdExecute(ExecuteFunction66.java:262) ~[geode-core-1.9.1.jar:na] at org.apache.geode.internal.cache.tier.sockets.command.ExecuteFunction70.cmdExecute(ExecuteFunction70.java:66) ~[geode-core-1.9.1.jar:na] at org.apache.geode.internal.cache.tier.sockets.BaseCommand.execute(BaseCommand.java:183) ~[geode-core-1.9.1.jar:na] at org.apache.geode.internal.cache.tier.sockets.ServerConnection.doNormalMessage(ServerConnection.java:851) ~[geode-core-1.9.1.jar:na] at org.apache.geode.internal.cache.tier.sockets.OriginalServerConnection.doOneMessage(OriginalServerConnection.java:75) ~[geode-core-1.9.1.jar:na] at org.apache.geode.internal.cache.tier.sockets.ServerConnection.run(ServerConnection.java:1227) ~[geode-core-1.9.1.jar:na] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) ~[na:na] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na] at org.apache.geode.internal.cache.tier.sockets.AcceptorImpl.lambda$initializeServerConnectionThreadPool$3(AcceptorImpl.java:616) ~[geode-core-1.9.1.jar:na] at org.apache.geode.internal.logging.LoggingThreadFactory.lambda$newThread$0(LoggingThreadFactory.java:121) ~[geode-core-1.9.1.jar:na] at java.base/java.lang.Thread.run(Thread.java:844) ~[na:na] Caused by: org.apache.geode.cache.RegionExistsException: /TitleContent at org.apache.geode.internal.cache.GemFireCacheImpl.createVMRegion(GemFireCacheImpl.java:2983) ~[geode-core-1.9.1.jar:na] at org.apache.geode.internal.cache.GemFireCacheImpl.basicCreateRegion(GemFireCacheImpl.java:2938) ~[geode-core-1.9.1.jar:na] at org.apache.geode.internal.cache.GemFireCacheImpl.createRegion(GemFireCacheImpl.java:2925) ~[geode-core-1.9.1.jar:na] at org.apache.geode.cache.RegionFactory.create(RegionFactory.java:755) ~[geode-core-1.9.1.jar:na] at org.springframework.data.gemfire.config.admin.functions.CreateRegionFunction.createRegion(CreateRegionFunction.java:51) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na] at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:279) ~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.data.gemfire.function.PojoFunctionWrapper.invokeTargetMethod(PojoFunctionWrapper.java:176) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.gemfire.function.PojoFunctionWrapper.execute(PojoFunctionWrapper.java:155) ~[spring-data-geode-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.apache.geode.internal.cache.tier.sockets.command.ExecuteFunction66.executeFunctionLocally(ExecuteFunction66.java:320) ~[geode-core-1.9.1.jar:na] at org.apache.geode.internal.cache.tier.sockets.command.ExecuteFunction66.cmdExecute(ExecuteFunction66.java:250) ~[geode-core-1.9.1.jar:na] ... 10 common frames omitted

      这次我再次标记// @ EnableClusterConfiguration并再次启动Spring Client。这次运行了,我再次尝试使用相同的POJO。成功了!
  • 完整日志:

    Initializing Spring DispatcherServlet 'dispatcherServlet' 2019-10-29 10:04:04.477 INFO 59413 --- [io-15050-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2019-10-29 10:04:04.483 INFO 59413 --- [io-15050-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 6 ms 2019-10-29 10:04:04.598 INFO 59413 --- [io-15050-exec-1] o.a.geode.pdx.internal.TypeRegistry : Caching PdxType[dsid=0, typenum=12150516 name=network.powerhouse.commercehost.model.TitleContent fields=[ id:Object:identity:0:idx0(relativeOffset)=0:idx1(vlfOffsetIndex)=-1 code:String:1:1:idx0(relativeOffset)=0:idx1(vlfOffsetIndex)=1 title:String:2:2:idx0(relativeOffset)=0:idx1(vlfOffsetIndex)=2 content:String:3:3:idx0(relativeOffset)=0:idx1(vlfOffsetIndex)=3]]

    1. 我尝试在控制器上成功获取带有GET其余端点的TitleContent列表。

  • 现在我关闭所有它们,然后重新启动它们。我尝试获取第5点中的列表,并像完整的日志中一样给我例外:
  • 具有路径[]的上下文中Servlet [dispatcherServlet]的Servlet.service()引发异常[请求处理失败;嵌套的异常是org.springframework.dao.DataAccessResourceFailureException:远程服务器位于192.168.100.8(SpringBasedCacheClientApplication:59853:loner):49745:69bf7c15:SpringBasedCacheClientApplication:执行远程查询时;嵌套的异常是org.apache.geode.cache.client.ServerOperationException:192.168.100.8上的远程服务器(SpringBasedCacheClientApplication:59853:loner):49745:69bf7c15:SpringBasedCacheClientApplication:执行远程查询时,根本原因是

    org.apache.geode.cache.query.RegionNotFoundException:找不到区域:/ TitleContent在org.apache.geode.cache.query.internal.DefaultQuery.checkQueryOnPR(DefaultQuery.java:464)〜[geode-core-1.9.1.jar:na]在org.apache.geode.cache.query.internal.DefaultQuery.execute(DefaultQuery.java:226)〜[geode-core-1.9.1.jar:na]在org.apache.geode.internal.cache.tier.sockets.BaseCommandQuery.processQueryUsingParams(BaseCommandQuery.java:120)〜[geode-core-1.9.1.jar:na]在org.apache.geode.internal.cache.tier.sockets.command.Query651.cmdExecute(Query651.java:135)〜[geode-core-1.9.1.jar:na]在org.apache.geode.internal.cache.tier.sockets.BaseCommand.execute(BaseCommand.java:183)〜[geode-core-1.9.1.jar:na]在org.apache.geode.internal.cache.tier.sockets.ServerConnection.doNormalMessage(ServerConnection.java:851)〜[geode-core-1.9.1.jar:na]在org.apache.geode.internal.cache.tier.sockets.OriginalServerConnection.doOneMessage(OriginalServerConnection.java:75)〜[geode-core-1.9.1.jar:na]在org.apache.geode.internal.cache.tier.sockets.ServerConnection.run(ServerConnection.java:1227)〜[geode-core-1.9.1.jar:na]在java.base / java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)〜[na:na]在java.base / java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:635)〜[na:na]在org.apache.geode.internal.cache.tier.sockets.AcceptorImpl.lambda $ initializeServerConnectionThreadPool $ 3(AcceptorImpl.java:616)〜[geode-core-1.9.1.jar:na]在org.apache.geode.internal.logging.LoggingThreadFactory.lambda $ newThread $ 0(LoggingThreadFactory.java:121)〜[geode-core-1.9.1.jar:na]在java.base / java.lang.Thread.run(Thread.java:844)[na:na]

    该区域似乎无法持久存储到磁盘。

    问题:

    在第3点抛出了异常,但确实创建了TitleContent区域。但是为什么抛出异常?

    有人可以查明我错过了什么,为什么@EnableClusterConfiguration在我的情况下表现不佳,以及为什么Region不能持久存储在磁盘上(根据参考手册,应该由DEFAULT DiskStore在7.12.7参考手册中将其持久存储到磁盘上)。对于这么长的问题,我感到抱歉。我只是无法将其缩短。

    谢谢您能帮助我,我真的很感激。

    完整的源代码列表:

    服务器:

    @SpringBootApplication @CacheServerApplication(locators="localhost[10334]", name="GeodeServerApplication" ) @EnableCacheServer(name="neptunus", autoStartup=true, hostnameForClients = "localhost", port = 48484) //@EnableCachingDefinedRegions //@EnableGemfireCaching @EnablePdx @EnableManager @EnableHttpService public class GeodeServerApplication { public static void main(String[] args) { SpringApplication.run(GeodeServerApplication.class, args); } }

    LOCATOR:

    @SpringBootApplication @LocatorApplication(port = 10334) public class GeodeLocatorApplication { public static void main(String[] args) { SpringApplication.run(GeodeLocatorApplication.class, args); } }

    客户:

    @SpringBootApplication @ClientCacheApplication(logLevel = "debug", locators = {@Locator(host = "localhost", port = 10334)}) @EnablePool(name="neptunusPool", servers=@Server(host="localhost", port=48484)) @EnableGemfireRepositories(basePackageClasses= {network.powerhouse.commercehost.repository.TitleContentRepository.class}) @EnableEntityDefinedRegions(basePackageClasses= { network.powerhouse.commercehost.model.TitleContent.class }) @ReplicateRegion @EnableClusterDefinedRegions @EnableCachingDefinedRegions @EnableGemfireCaching @EnableIndexing //@EnableClusterConfiguration @EnablePdx public class CommerceHostGeodeApplication { public static void main(String[] args) { SpringApplication.run(CommerceHostGeodeApplication.class, args); } }

    客户控制器:

    @RestController public class TitleContentController { @Autowired TitleContentService service; @PostMapping("/titlecontent") TitleContent postTitleContent(@RequestBody TitleContent titleContent) { return service.save(titleContent); } @GetMapping("titlecontent") List<TitleContent> getTitleContentByCode(@RequestParam("code") String code){ return service.findByCode(code); } }

    客户存储库:

    @Region("TitleContent") public interface TitleContentRepository extends CrudRepository<TitleContent, Long> { @Trace List<TitleContent> findByCode(String code); }

    客户服务:

    public interface TitleContentServiceInterface { public TitleContent save(TitleContent titleContent); public void delete(TitleContent titleContent); public TitleContent findById(Long id); List<TitleContent> findByCode(String code); } @Service public class TitleContentService implements TitleContentServiceInterface{ @Autowired TitleContentRepository repo; @Override public TitleContent save(TitleContent titleContent) { return repo.save(titleContent); } @Override public void delete(TitleContent titleContent) { repo.delete(titleContent); } @Override public TitleContent findById(Long id) { return repo.findById(id).get(); } @Override public List<TitleContent> findByCode(String code) { return repo.findByCode(code); } }

    POJO:

    @Region("TitleContent") public class TitleContent { @Id private Long id; @Indexed private String code; private String title; private String content; public TitleContent(Long id, String code, String title, String content) { super(); this.id = id; this.code = code; this.title = title; this.content = content; } public TitleContent() { super(); } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } @Override public String toString() { return "TitleContent [id=" + id + ", code=" + code + ", title=" + title + ", content=" + content + "]"; } }

    依赖关系:

    <dependency> <groupId>org.springframework.geode</groupId> <artifactId>spring-geode-starter</artifactId> <version>1.2.0.RELEASE</version> </dependency>

    弹簧靴版本:

    <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.0.RELEASE</version>

    [我观看了来自Springone Platform和John Blum的演讲者,并有兴趣尝试Geode / Gemfire设置,但按照Apache Data Geode参考指南的Spr​​ing Data中所述进行设置,所以我制作...
    java spring spring-boot gemfire geode
    1个回答
    0
    投票
    © www.soinside.com 2019 - 2024. All rights reserved.