我有一个托管在PCF上的springboot应用程序,试图连接到PCC(pivotal cloud cache)。我已经创建了一个PCC实例,并将其绑定到我的应用程序,并将该应用程序推送到云代工。我已经向springboot添加了所有必需的gemfire starter依赖项,看起来它能够从VCAP_SERVICES读取定位器和服务器信息。但是,我在spring boot应用程序启动时看到以下错误。
Error prefilling connections : org.apache.geode.security.AuthenticationRequiredException: No security credentials are provided
org.apache.geode.security.AuthenticationRequiredException: No security credentials are provided
at org.apache.geode.internal.cache.tier.sockets.Handshake.readMessage(Handshake.java:320)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.geode.cache.Region]: Failed to create Region for cache [TestRegion]; nested exception is org.apache.geode.security.AuthenticationRequiredException: No security credentials are provided以下是我的依赖项列表
<dependency>
<groupId>org.springframework.geode</groupId>
<artifactId>spring-gemfire-starter</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-gemfire</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.pivotal.gemfire</groupId>
<artifactId>geode-core</artifactId>
<version>9.5.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.pivotal.gemfire</groupId>
<artifactId>geode-common</artifactId>
<version>9.5.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.pivotal.gemfire</groupId>
<artifactId>geode-cq</artifactId>
<version>9.5.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.pivotal.gemfire</groupId>
<artifactId>geode-lucene</artifactId>
<version>9.5.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.pivotal.gemfire</groupId>
<artifactId>geode-wan</artifactId>
<version>9.5.4</version>
<scope>compile</scope>
</dependency>@Configuration
@ClientCacheApplication(name = "Test", logLevel = "info")
@EnableCachingDefinedRegions(
clientRegionShortcut = ClientRegionShortcut.PROXY,
serverRegionShortcut = RegionShortcut.REPLICATE_HEAP_LRU)
@EnableClusterAware
@EnablePdx
public class CloudConfiguration {}我相信,我拥有的Springboot gemfire starter依赖项已经足够好,可以自动从VCAP_SERVICES读取安全证书,而不需要任何手动操作。但是,我看到它没有拿起证书,不确定为什么有下面所有的依赖。有人能帮帮忙吗?谢谢
发布于 2020-04-22 05:25:45
好的..。
首先,请参阅我的answer,它是关于应用程序依赖项的最后一个SO post的答案。正确地声明应用程序依赖关系是我回答的中心主题。
接下来,在使用GemFire时,Spring Data PCC (SDG)本身不会在像PCF这样的托管环境中“自动”处理身份验证。为此,您绝对需要用于Apache Geode或Pivotal GemFire (SBDG)的Spring Boot,在您的示例中,".. for Pivotal GemFire",从技术上讲,还需要org.springframework.geode:spring-gemfire-starter依赖项,这是您唯一需要的依赖项。确保按照我在上一个post中的指示对齐版本。
基于上面的配置,您显式地“覆盖了”客户端安全配置和由SBDG提供的自动配置,因为您显式地在CloudConfiguration类上声明了@ClientCacheApplication注释。
为什么?
再说一次,这是GemFire/Geode的事情,不是Spring的事情,但是所有涉及GemFire/Geode (客户端/服务器、P2P、广域网等)形式的“安全性”必须在缓存对象被构造和初始化之前正确地配置和设置。
如果缓存对象是由用户/应用程序配置提供的,那么SBDG的GemFire/Geode client Security的自动配置将不会被应用()。请参阅here (当然还有here)。
从技术上讲,这与GemFire/Geode“安全配置”几乎完全通过GemFire/Geode属性配置有关。这些属性必须在构造缓存之前声明/设置,因为它们是在启动时传递给缓存创建的。如果未提供它们,则安全配置将不会应用。如果您稍后在运行时提供Security属性,无论是否使用Spring (例如,直接使用GemFire/Geode API ),结果都是相同的!
GemFire/Geode有一个非常特定的初始化顺序: Auth,TLS/SSL,内存管理,这,这就是为什么SBDG自动配置已经被精心设计,以确保遵循正确的初始化顺序。
此外,无论是否(显式地)使用SDG的配置注释,而不是使用JavaConfig在Spring上下文中声明显式bean,效果都是相同的,因为SDG配置注释隐式地为您声明那些bean,这导致“覆盖”Spring Boot提供的自动配置,特别是SBDG。
无论是GemFire/Geode还是非GemFire/Geode,这都是一样的。如果您显式声明了一个SQL,那么当您的应用程序类路径上有一个嵌入式数据库( DataSource或H2)时,您就是在告诉DataSource重写所提供的DataSource。
它的概念是“约定重于配置”(通过简单地声明对应用程序类路径的依赖关系来自动启用特性),但也是为了在应用程序需求偏离默认设置时快速摆脱阻碍,并且您必须显式声明特定类型的bean定义,以便根据应用程序需求更改配置,这必然会禁用Spring Boot提供的自动配置,否则,您将拥有不明确和/或冲突的配置(即,哪种配置就是它)。一般来说,Spring框架甚至不允许这样做。
同样,删除@ClientCacheApplication和@EnablePdx。在SBDG中不需要它们。然而,正是@ClientCacheApplication注释在这里给您带来了问题。
总而言之,所有这些在参考文档中都有详细的解释:
尤其要注意第4章中的Overriding Auto-configuration。
希望这能有所帮助!
https://stackoverflow.com/questions/61129237
复制相似问题