Spring认证中国教育管理中心-Apache Geode 的 Spring 数据教程十五

本文档介绍了Apache Geode与Spring Data的注解配置,包括@EnableAuth(已弃用)、@EnableAutoRegionLookup(不建议使用)等。重点强调了新注解模型的便利性,同时提到仍可结合Java配置或XML配置使用。文章提供了快速入门的注解配置示例,如@ClientCacheApplication、@CacheServerApplication等,适用于配置ClientCache和PeerCache应用程序,并可启用各种服务如定位器、管理器、HTTP服务器、Memcached和Redis服务器。
摘要由CSDN通过智能技术生成

原标题:Spring认证中国教育管理中心-Apache Geode 的 Spring 数据教程十五(Spring中国教育管理中心)

Spring认证中国教育管理中心-Apache Geode 的 Spring 数据教程十五

 

6.18.2.其他基于配置的注释

本参考文档中未讨论以下 SDG 注释,要么是因为该注释支持 Apache Geode 已弃用的功能,要么是因为有更好的替代方法来完成该注释提供的功能:

  • @EnableAuth:启用 Apache Geode 的旧身份验证和授权安全模型。(已弃用。Apache Geode 的新集成安全框架可以通过使用 SDG 的@EnableSecurity注释在客户端和服务器上启用 ,如“配置安全性”中所述。)
  • @EnableAutoRegionLookup: 不建议。本质上,此注解支持查找在外部配置元数据(例如cache.xml应用于服务器时的集群配置)中定义的区域,并自动将这些区域注册为 Spring 容器中的 bean。此注释对应<gfe:auto-region-lookup> 于 SDG 的 XML 命名空间中的元素。可以在此处找到更多详细信息。当使用 Spring 和 Spring Data for Apache Geode 时,用户通常应该更喜欢 Spring 配置。请参阅“配置区域”和“配置集群配置推送”。
  • @EnableBeanFactoryLocator:启用 SDGGemfireBeanFactoryLocator功能,该功能仅在使用外部配置元数据(例如,cache.xml)时有用。例如,如果您在 中定义的区域CacheLoader上定义 a cache.xml,您仍然可以CacheLoader使用DataSourceSpring 配置中定义的关系数据库 bean自动装配它。此注释利用此 SDG功能,如果您有大量旧配置元数据(例如cache.xml文件),则此注释 可能会很有用。
  • @EnableGemFireAsLastResource:在Global - JTA Transaction Management with Apache Geode 中讨论。
  • @EnableMcast:启用 Apache Geode 的旧对等发现机制,该机制使用基于 UDP 的多播网络。(已弃用。请改用 Apache Geode Locators。请参阅“配置嵌入式定位器”。
  • @EnableRegionDataAccessTracing: 用于调试目的。该注解通过注册代理所有在 Spring 容器中声明为 bean 的 Region 的 AOP Aspect,拦截 Region 操作并记录事件来跟踪在 Region 上执行的所有数据访问操作。

6.19.结论

正如我们在前几节中了解到的,Spring Data for Apache Geode 的新的基于注解的配置模型提供了巨大的力量。我们希望,不辜负使它更容易为你的目标快速上手轻松 使用Apache的Geode与春天的时候。

请记住,当您使用新的注解时,您仍然可以使用 Java 配置或 XML 配置。您甚至可以通过 在 Spring或类上使用 Spring@Import 和@ImportResource注解来组合所有三种方法。一旦您明确提供了一个 bean 定义,否则 Spring Data for Apache Geode 会使用其中一个注解提供,基于注解的配置就会退出。@Configuration@SpringBootApplication

在某些情况下,您甚至可能需要回退到 Java 配置,因为在这种Configurers情况下,要处理更复杂的或有条件的配置逻辑,这些逻辑不容易用注释表达或无法单独使用注释来完成。不要惊慌。这种行为是可以预料的。

例如,另一种需要 Java 或 XML 配置的情况是在配置 Apache Geode WAN 组件时,该组件目前没有任何注释配置支持。但是,定义和注册 WAN 组件只需要在 Spring或类的 Java 配置中使用
org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean 和org.springframework.data.gemfire.wan.GatewaySenderFactoryBeanAPI 类(推荐)。@Configuration@SpringBootApplication

注释并不是为了处理所有情况。这些注释旨在帮助您 尽可能快速、轻松地启动和运行,尤其是在开发过程中。

我们希望您会喜欢这些新功能!

6.20.基于注解的配置快速入门

以下部分概述了 SDG 注释,以便快速入门。

所有注解都提供了额外的配置属性以及相关的属性, 以便在运行时方便地自定义 Apache Geode 的配置和行为。但是,一般来说,使用特定的 Apache Geode 功能不需要任何属性或相关属性。只需声明注释以启用该功能即可完成。

6.20.1.配置ClientCache应用程序

要配置和引导 Apache GeodeClientCache应用程序,请使用以下命令:

@SpringBootApplication
@ClientCacheApplication
public class ClientApplication {

  public static void main(String[] args) {
    SpringApplication.run(ClientApplication.class, args);
  }
}

请参阅@
ClientCacheApplicationJavadoc。

@Target ( value = TYPE )
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
 @Configuration 
 @Import ( value = ClientCacheConfiguration.class )
公共@interface ClientCacheApplication

该ClientCacheApplication注释使基于 Spring Data GemFire/Geode 的应用程序成为 GemFire/Geode 缓存客户端(即ClientCache)。

6.20.2.配置对等Cache应用程序

要配置和引导 Apache Geode PeerCache应用程序,请使用以下命令:

@SpringBootApplication
@PeerCacheApplication
public class ServerApplication {

  public static void main(String[] args) {
    SpringApplication.run(ServerApplication.class, args);
  }
}

如果您想启用CacheServer允许ClientCache应用程序连接到此服务器的 ,那么只需将@PeerCacheApplication注释替换为注释即可@CacheServerApplication。这将开始CacheServer在“localhost”运行,侦听默认的CacheServer端口40404。

请参阅@
CacheServerApplicationJavadoc。


@target(值= TYPE)
  @Retention(值= RUNTIME)
  @Inherited 
 @Documented 
 @Configuration 
 @Import(值= CacheServerConfiguration.class)
公共@interface CacheServerApplication

CacheServerApplication 注释CacheServer在基于 Spring Data GemFire 的应用程序中启用嵌入式 GemFire 实例。此外,这也意味着Cache必须存在嵌入式 GemFire 对等点,因此将在应用程序上下文中作为 Spring bean 进行配置、构造和初始化。

请参阅@
PeerCacheApplicationJavadoc。


@target(值= { ANNOTATION_TYPE,TYPE })
  @Retention(值= RUNTIME)
  @Inherited 
 @Documented 
 @Configuration 
 @Import(值= PeerCacheConfiguration.class)
公共@interface PeerCacheApplication

该PeerCacheApplication注释Cache 在基于 Spring Data GemFire 的应用程序中启用嵌入式 GemFire 对等实例。

6.20.3.配置嵌入式定位器

注释您的 Spring@PeerCacheApplication或@CacheServerApplication类@EnableLocator以启动一个嵌入式定位器,该定位器绑定到侦听默认定位器端口的所有 NIC 10334,如下所示:

@SpringBootApplication
@CacheServerApplication
@EnableLocator
public class ServerApplication {

  public static void main(String[] args) {
    SpringApplication.run(ServerApplication.class, args);
  }
}

@EnableLocator 只能与 Apache Geode 服务器应用程序一起使用。

请参阅@EnableLocatorJavadoc。

@target(值= TYPE)
  @Retention(值= RUNTIME)
  @Inherited 
 @Documented 
 @Import(值= LocatorConfiguration.class)
  @UsesGemFireProperties
公共@interface EnableLocator

该EnableLocator注解配置一个弹簧@Configuration注释Class 启动嵌入式枢纽的GemFire /阿帕奇的GeodeLocator在该集群成员的服务。但是,即使Annotation存在,也可以使用
spring.data.gemfire.service.http.enabled 属性在 application.properties 外部启用/禁用嵌入式 Pivotal GemFire/Apache Geode Locator 服务,从而用作切换。

6.20.4.配置嵌入式管理器

注释您的 Spring@PeerCacheApplication或@CacheServerApplication类@EnableManager以启动绑定到所有 NIC 的嵌入式管理器,这些 NIC 侦听默认管理器端口,1099如下所示:

@SpringBootApplication
@CacheServerApplication
@EnableManager
public class ServerApplication {

  public static void main(String[] args) {
    SpringApplication.run(ServerApplication.class, args);
  }
}

@EnableManager 只能与 Apache Geode 服务器应用程序一起使用。

请参阅@EnableManagerJavadoc。

@Target ( value = TYPE )
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
 @Import ( value = ManagerConfiguration.class )
  @UsesGemFireProperties 
public @interface EnableManager

该EnableManager注解标记了一个 Spring,该@Configuration注解Class 用于在该集群成员中配置、嵌入和启动 Pivotal GemFire/Apache Geode Manager 服务。只需Annotation 在您的 Spring 应用程序@Configurationannotated上指定此项,即可自动将 jmx-manager 设置为 true Class。但是,即使Annotation存在,也可以使用
spring.data.gemfire.manager.enabled 属性在 application.properties 外部启用/禁用嵌入式 Pivotal GemFire/Apache Geode Manager ,从而用作切换。

6.20.5.配置嵌入式 HTTP 服务器

注释您的 Spring@PeerCacheApplication或@CacheServerApplication类@EnableHttpService以启动监听端口的嵌入式 HTTP 服务器 (Jetty) 7070,如下所示:

@SpringBootApplication
@CacheServerApplication
@EnableHttpService
public class ServerApplication {

  public static void main(String[] args) {
    SpringApplication.run(ServerApplication.class, args);
  }
}

@EnableHttpService 只能与 Apache Geode 服务器应用程序一起使用。

请参阅@EnableHttpServiceJavadoc。

@Target ( value = TYPE )
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
 @Import ( value = HttpServiceConfiguration.class )
  @UsesGemFireProperties 
public @interface EnableHttpService

该EnableHttpService注释标记了一个 Spring@Configuration 注释,Class用于配置和启用 Pivotal GemFire/Apache Geode 的嵌入式 HTTP 服务。通过使用它Annotation,可以在启动时启用嵌入式 HTTP 服务,如 Pulse、管理 REST API 和开发人员 REST API。但是,嵌入式 Pivotal GemFire/Apache Geode HTTP 服务和所有相关服务(例如 Pulse)可以在 application.properties 中使用
spring.data.gemfire.service.http.enabled 属性在外部启用/禁用,即使Annotation存在,从而作为切换。

6.20.6.配置嵌入式 Memcached 服务器

注释您的 Spring@PeerCacheApplication或@CacheServerApplication类@EnableMemcachedServer以启动监听端口的嵌入式 Memcached 服务器 (Gemcached) 11211,如下所示:

@SpringBootApplication
@CacheServerApplication
@EnableMemcachedServer
public class ServerApplication {

  public static void main(String[] args) {
    SpringApplication.run(ServerApplication.class, args);
  }
}

@EnableMemcachedServer 只能与 Apache Geode 服务器应用程序一起使用。

请参阅@
EnableMemcachedServerJavadoc。

@Target ( value = TYPE )
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
 @Import ( value = MemcachedServerConfiguration.class )
  @UsesGemFireProperties 
public @interface EnableMemcachedServer

该EnableMemcachedServer注解标记了一个 Spring 被@Configuration 注解Class以在该集群成员中启动嵌入式 Memcached Server (Gemcached) 服务。Gemcached 服务实现了 Memcached 服务器协议,使 Memcached 客户端能够连接到 Pivotal GemFire 或 Apache Geode 服务器并与之通信。但是,即使Annotation存在,也可以使用
spring.data.gemfire.service.memcached.enabled 属性在 application.properties 外部启用/禁用嵌入式 Pivotal GemFire/Apache Geode Memcached 服务,从而用作切换。

6.20.7.配置嵌入式Redis服务器

注释您的 Spring@PeerCacheApplication或@CacheServerApplication类@EnableRedisServer以启动监听端口的嵌入式 Redis 服务器6379,如下所示:

@SpringBootApplication
@CacheServerApplication
@EnableRedisServer
public class ServerApplication {

  public static void main(String[] args) {
    SpringApplication.run(ServerApplication.class, args);
  }
}

@EnableRedisServer 只能与 Apache Geode 服务器应用程序一起使用。

您必须
org.apache.geode:geode-redis在 Spring [Boot] 应用程序类路径上显式声明该模块。

请参阅@EnableRedisServerJavadoc。

@target(值= TYPE)
  @Retention(值= RUNTIME)
  @Documented 
 @Inherited 
 @Import(值= RedisServerConfiguration.class)
  @UsesGemFireProperties
公共@interface EnableRedisServer

该EnableRedisServer注解标记了一个 Spring 被@Configuration注解Class 以在该集群成员中嵌入 Redis 服务。Redis 服务实现了 Redis 服务器协议,使 Redis 客户端能够连接到 Pivotal GemFire 或 Apache Geode 并与之互操作。但是,即使Annotation存在,也可以使用
spring.data.gemfire.service.redis.enabled 属性在 application.properties 外部启用/禁用嵌入式 Pivotal GemFire/Apache Geode Redis 服务,从而用作切换。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

技能咖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值