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

4次阅读

共计 7615 个字符,预计需要花费 20 分钟才能阅读完成。

原题目:Spring 认证中国教育管理中心 -Apache Geode 的 Spring 数据教程十五(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 服务,从而用作切换。

正文完
 0