前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring认证中国教育管理中心-Apache Geode 的 Spring 数据教程十六

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

原创
作者头像
IT胶囊
发布2021-12-28 15:02:14
2420
发布2021-12-28 15:02:14
举报
文章被收录于专栏:IT技能应用

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

6.20.8.配置日志记录

要配置或调整 Apache Geode 日志记录,请使用 注释您的 Spring、Apache Geode 客户端或服务器应用程序类@EnableLogging,如下所示:

代码语言:javascript
复制
@SpringBootApplication
@ClientCacheApplication
@EnableLogging(logLevel="trace")
public class ClientApplication {

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

默认log-level为“配置”。此外,此注释不会调整应用程序中的日志级别,仅适用于 Apache Geode。

请参阅@EnableLoggingJavadoc。

代码语言:javascript
复制
@target(值= TYPE)
  @Retention(值= RUNTIME)
  @Inherited 
 @Documented 
 @Import(值= LoggingConfiguration.class)
  @UsesGemFireProperties
公共@interface EnableLogging

该EnableLogging注释标记了一个 Spring@Configuration注释,Class 用于配置和启用 Pivotal GemFire/Apache Geode 系统日志记录。

6.20.9.配置统计

要在运行时收集 Apache Geode 统计信息,请使用 注释您的 Spring、Apache Geode 客户端或服务器应用程序类@EnableStatistics,如下所示:

代码语言:javascript
复制
@SpringBootApplication
@ClientCacheApplication
@EnableStatistics
public class ClientApplication {

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

请参阅@EnableStatisticsJavadoc。

代码语言:javascript
复制
@Target ( value = TYPE )
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
 @Import ( value = StatisticsConfiguration.class )
  @UsesGemFireProperties 
public @interface EnableStatistics

该EnableStatistics注解标记了一个 Spring,该@Configuration注解Class 用于配置和启用正在运行的 Pivotal GemFire/Apache Geode 系统的统计信息和运行时指标。将 statistic-sampling-enabled 设置为 true。

6.20.10。配置PDX

要启用 Apache Geode PDX 序列化,请使用 注释您的 Spring、Apache Geode 客户端或服务器应用程序类@EnablePdx,如下所示:

代码语言:javascript
复制
@SpringBootApplication
@ClientCacheApplication
@EnablePdx
public class ClientApplication {

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

Apache Geode PDX 序列化是 Java 序列化的替代方案,具有许多附加优势。一方面,它可以让您的所有应用程序域模型类型可序列化,而无需实现 java.io.Serializable.

默认情况下,SDG 配置MappingPdxSerializer序列化您的应用程序域模型类型,这不需要任何开箱即用的特殊配置来正确识别需要序列化的应用程序域对象,然后执行序列化,因为逻辑inMappingPdxSerializer基于 Spring Data 的映射基础架构。

请参阅@EnablePdxJavadoc。

代码语言:javascript
复制
@target(值= TYPE)
  @Retention(值= RUNTIME)
  @Inherited 
 @Documented 
 @Import(值= PdxConfiguration.class)
公共@interface EnablePdx

该EnablePdx注解标记了一个 Spring 进行@Configuration注解,Class 以在该对等缓存、集群成员或缓存客户端应用程序中启用 Apache Geode PDX 特性和功能。

6.20.11。配置 SSL

要启用 Apache Geode SSL,请使用 注释您的 Spring、Apache Geode 客户端或服务器应用程序类@EnableSsl,如下所示:

代码语言:javascript
复制
@SpringBootApplication
@ClientCacheApplication
@EnableSsl(components = SERVER)
public class ClientApplication {

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

Apache Geode 至少要求您使用适当的配置属性或属性指定密钥库和信任库。密钥库和信任库配置属性或属性可能引用同一个 KeyStore文件。此外,KeyStore如果文件已受保护,您将需要指定用户名和密码才能访问该文件。

Apache Geode SSL 允许您配置需要 TLS 的系统特定组件,例如客户端/服务器、定位器、网关等。或者,您可以使用“ALL”指定 Apache Geode 的所有组件使用 SSL。

请参阅@EnableSslJavadoc。

代码语言:javascript
复制
@target(值= TYPE)
  @Retention(值= RUNTIME)
  @Inherited 
 @Documented 
 @Import(值= SslConfiguration.class)
  @UsesGemFireProperties
公共@interface EnableSsl

该EnableSsl注释标记了一个 Spring@Configuration注释,Class 用于配置和启用 Pivotal GemFire/Apache Geode 的 TCP/IP 套接字 SSL。

6.20.12。配置安全

要启用 Apache Geode 安全性,请使用 注释您的 Spring、Apache Geode 客户端或服务器应用程序类@EnableSecurity,如下所示:

代码语言:javascript
复制
@SpringBootApplication
@ClientCacheApplication
@EnableSecurity
public class ClientApplication {

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

在服务器上,您必须配置对身份验证凭据的访问。您可以实现 Apache Geode SecurityManager接口或声明 1 个或多个 Apache Shiro Realms。有关更多详细信息,请参阅配置服务器安全性。

在客户端,您必须配置用户名和密码。有关 更多详细信息,请参阅配置客户端安全性。

请参阅@EnableSecurityJavadoc。

代码语言:javascript
复制
@target(值= TYPE)
  @Retention(值= RUNTIME)
  @Inherited 
 @Documented 
 @Import(值= { ApacheShiroSecurityConfiguration.class,AutoConfiguredAuthenticationConfiguration.class,GeodeIntegratedSecurityConfiguration.class })
  @UsesGemFireProperties
公共@interface EnableSecurity

该EnableSecurity注释标记了一个 Spring@Configuration注释,Class 用于配置和启用 Pivotal GemFire/Apache Geode 的安全功能,以进行身份​验证、授权和后处理。

6.20.13。配置 Apache Geode 属性

要配置面向功能的 SDG 配置注释未涵盖的其他低级 Apache Geode 属性,请使用 注释您的 Spring、Apache Geode 客户端或服务器应用程序类@GemFireProperties,如下所示:

代码语言:javascript
复制
@SpringBootApplication
@PeerCacheApplication
@EnableGemFireProperties(
    cacheXmlFile = "/path/to/cache.xml",
    conserveSockets = true,
    groups = "GroupOne",
    remoteLocators = "lunchbox[11235],mailbox[10101],skullbox[12480]"
)
public class ServerApplication {

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

一些 Apache Geode 属性仅用于客户端,而其他一些仅用于服务器端。请查看 Apache Geode文档以正确使用每个属性。

请参阅@ EnableGemFirePropertiesJavadoc。

代码语言:javascript
复制
@target(值= TYPE)
  @Retention(值= RUNTIME)
  @Inherited 
 @Documented 
 @Import(值= GemFirePropertiesConfiguration.class)
  @UsesGemFireProperties
公共@interface EnableGemFireProperties

该EnableGemFireProperties注释标记了一个 Spring@Configuration 注释类,用于在 [Spring Boot] 应用程序启动期间在运行时配置 GemFire/Geode 系统属性。

6.20.14。配置缓存

使用Apache的Geode作为缓存提供者在Spring的缓存抽象,并且有SDG自动创建的Apache的Geode地区为您的应用程序服务组件所需的高速缓存,然后注释你的春天,阿帕奇的Geode客户端或服务器应用程序类@EnableGemfireCaching和@ EnableCachingDefinedRegions,如下所示:

代码语言:javascript
复制
@SpringBootApplication
@ClientCacheApplication
@EnableCachingDefinedRegions
@EnableGemfireCaching
public class ClientApplication {

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

然后,继续定义需要缓存的应用服务,如下:

代码语言:javascript
复制
@Service
public class BookService {

    @Cacheable("Books")
    public Book findBy(ISBN isbn) {
        ...
    }
}

@ EnableCachingDefinedRegions是可选的。也就是说,您可以根据需要手动定义您的区域。

请参阅@ EnableCachingDefinedRegionsJavadoc。

代码语言:javascript
复制
@target(值= TYPE)
  @Retention(值= RUNTIME)
  @Inherited 
 @Documented 
 @EnableGemfireCaching 
 @Import(值= CachingDefinedRegionsConfiguration.class)
公共@interface EnableCachingDefinedRegions

该 EnableCachingDefinedRegions注解标记了一个 Spring@Configuration应用程序注解类,以支持Regions基于 Spring 的缓存抽象注解应用于应用程序服务方法和类型的 GemFire/Geode 的创建。此外,这个注解通过 SDG 的注解启用 Spring 的缓存抽象EnableGemfireCaching,它声明 Spring 的EnableCaching注解以及声明 SDG GemfireCacheManagerbean 定义。

请参阅@ EnableGemfireCachingJavadoc。

代码语言:javascript
复制
@target(值= TYPE)
  @Retention(值= RUNTIME)
  @Inherited 
 @Documented 
 @Import(值= GemfireCachingConfiguration.class)
公共@interface EnableGemfireCaching

该EnableGemfireCaching注释使 Pivotal GemFire 或 Apache Geode 作为 Spring 的缓存抽象中的缓存提供程序。

6.20.15。为持久性应用程序配置区域、索引、存储库和实体

为了简化创建 Spring、Apache Geode 持久客户端或服务器应用程序的工作,请使用@ EnableEntityDefinedRegions,@EnableGemfireRepositories和注释您的应用程序类@EnableIndexing,如下所示:

代码语言:javascript
复制
@SpringBootApplication
@ClientCacheApplication
@EnableEntityDefinedRegions(basePackageClasses = Book.class)
@EnableGemfireRepositories(basePackageClasses = BookRepository.class)
@EnableIndexing
public class ClientApplication {

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

使用@ EnableEntityDefinedRegions注解时需要@EnableIndexing注解。有关更多详细信息,请参阅配置索引。

接下来,定义您的实体类并使用@Region映射注释来指定将存储您的实体的区域。使用@Indexed注释定义应用程序查询中使用的实体字段的索引,如下所示:

代码语言:javascript
复制
package example.app.model;

import ...;

@Region("Books")
public class Book {

  @Id
  private ISBN isbn;

  @Indexed;
  private Author author;

  @Indexed
  private LocalDate published;

  @LuceneIndexed
  private String title;

}

该@Region("Books")实体类注释用于通过@ EnableEntityDefinedRegions确定由应用程序所需的区域。有关 更多详细信息,请参阅配置特定于类型的区域和POJO 映射。

最后,使用简单的查询来定义您的 CRUD 存储库以持久化和访问Books,如下所示:

代码语言:javascript
复制
package example.app.repo;

import ...;

public interface BookRepository extends CrudRepository {

  List<Book> findByAuthorOrderByPublishedDesc(Author author);

}

请参阅@ EnableEntityDefinedRegionsJavadoc。

代码语言:javascript
复制
@Target ( value = TYPE )
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
 @Import ( value = IndexConfiguration.class )
公共@interface EnableEntityDefinedRegions

该 EnableEntityDefinedRegions注释标记了一个 Spring@Configuration应用程序注释类,以支持Regions基于应用程序持久实体创建 GemFire/Geode 。

请参阅@ EnableGemfireRepositoriesJavadoc。

代码语言:javascript
复制
@target(值= TYPE)
  @Retention(值= RUNTIME)
  @Documented 
 @Inherited 
 @Import(值= GemfireRepositoriesRegistrar.class)
公共@interface EnableGemfireRepositories

启用 Apache Geode、Spring Data 的注释Repositories。

请参阅@EnableIndexingJavadoc。

代码语言:javascript
复制
@Target ( value = TYPE )
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
public @interface EnableIndexing

该EnableIndexing注释标记的春天@Configuration注释应用类启用的GemFire /的Geode的创建Indexes和LuceneIndexes基于应用的持久性实体字段/属性注释,比如@Id,@Indexed 和@LuceneIndex注释。

请参阅@RegionJavadoc。

代码语言:javascript
复制
@Target ( value = TYPE )
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
public @interface Region

Annotation声明Region将存储应用程序持久实体的位置。

请参阅@IndexedJavadoc。

代码语言:javascript
复制
@Target ( value ={ FIELD , METHOD })
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
public @interface Indexed

该Indexed注释被用于索引,它创建了一个的GemFire /的Geode上的GemFire /的Geode 。GemfirePersistentEntity GemfirePersistentPropertyIndexRegion

请参阅@LuceneIndexedJavadoc。

代码语言:javascript
复制
@Target ( value ={ FIELD , METHOD })
  @Retention ( value = RUNTIME )
  @Inherited 
 @Documented 
public @interface LuceneIndexed

该LuceneIndexed注释被用于索引,创建的GemFire /的Geode 上的GemFire /的Geode 。GemfirePersistentEntity GemfirePersistentPropertyLuceneIndexRegion

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 6.20.8.配置日志记录
  • 6.20.9.配置统计
  • 6.20.10。配置PDX
  • 6.20.11。配置 SSL
  • 6.20.12。配置安全
  • 6.20.13。配置 Apache Geode 属性
  • 6.20.14。配置缓存
  • 6.20.15。为持久性应用程序配置区域、索引、存储库和实体
相关产品与服务
文件存储
文件存储(Cloud File Storage,CFS)为您提供安全可靠、可扩展的共享文件存储服务。文件存储可与腾讯云服务器、容器服务、批量计算等服务搭配使用,为多个计算节点提供容量和性能可弹性扩展的高性能共享存储。腾讯云文件存储的管理界面简单、易使用,可实现对现有应用的无缝集成;按实际用量付费,为您节约成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档