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

8次阅读

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

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

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

@SpringBootApplication
@ClientCacheApplication
@EnableLogging(logLevel=”trace”)
public class ClientApplication {

public static void main(String[] args) {

SpringApplication.run(ClientApplication.class, args);

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

请参阅 @EnableLoggingJavadoc。

@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,如下所示:

@SpringBootApplication
@ClientCacheApplication
@EnableStatistics
public class ClientApplication {

public static void main(String[] args) {

SpringApplication.run(ClientApplication.class, args);

}
}
请参阅 @EnableStatisticsJavadoc。

@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,如下所示:

@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。

@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,如下所示:

@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。

@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,如下所示:

@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。

@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,如下所示:

@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。

@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,如下所示:

@SpringBootApplication
@ClientCacheApplication
@EnableCachingDefinedRegions
@EnableGemfireCaching
public class ClientApplication {

public static void main(String[] args) {

SpringApplication.run(ClientApplication.class, args);

}
}
而后,持续定义须要缓存的应用服务,如下:

@Service
public class BookService {

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

}
@
EnableCachingDefinedRegions 是可选的。也就是说,您能够依据须要手动定义您的区域。

请参阅 @
EnableCachingDefinedRegionsJavadoc。

@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。

@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,如下所示:

@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 正文定义应用程序查问中应用的实体字段的索引,如下所示:

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,如下所示:

package example.app.repo;

import …;

public interface BookRepository extends CrudRepository {

List<Book> findByAuthorOrderByPublishedDesc(Author author);

}
请参阅 @
EnableEntityDefinedRegionsJavadoc。

@Target (value = TYPE)
@Retention (value = RUNTIME)
@Inherited
@Documented
@Import (value = IndexConfiguration.class)
公共 @interface EnableEntityDefinedRegions

EnableEntityDefinedRegions 正文标记了一个 Spring@Configuration 应用程序正文类,以反对 Regions 基于应用程序长久实体创立 GemFire/Geode。

请参阅 @
EnableGemfireRepositoriesJavadoc。

@target(值 = TYPE)
@Retention(值 = RUNTIME)
@Documented
@Inherited
@Import(值 = GemfireRepositoriesRegistrar.class)
公共 @interface EnableGemfireRepositories
启用 Apache Geode、Spring Data 的正文 Repositories。

请参阅 @EnableIndexingJavadoc。

@Target (value = TYPE)
@Retention (value = RUNTIME)
@Inherited
@Documented
public @interface EnableIndexing
该 EnableIndexing 正文标记的春天 @Configuration 正文利用类启用的 GemFire / 的 Geode 的创立 Indexes 和 LuceneIndexes 基于利用的持久性实体字段 / 属性正文,比方 @Id,@Indexed 和 @LuceneIndex 正文。

请参阅 @RegionJavadoc。

@Target (value = TYPE)
@Retention (value = RUNTIME)
@Inherited
@Documented
public @interface Region
Annotation 申明 Region 将存储应用程序长久实体的地位。

请参阅 @IndexedJavadoc。

@Target (value ={ FIELD , METHOD})
@Retention (value = RUNTIME)
@Inherited
@Documented
public @interface Indexed
该 Indexed 正文被用于索引,它创立了一个的 GemFire / 的 Geode 上的 GemFire / 的 Geode。GemfirePersistentEntity
GemfirePersistentPropertyIndexRegion

请参阅 @LuceneIndexedJavadoc。

@Target (value ={ FIELD , METHOD})
@Retention (value = RUNTIME)
@Inherited
@Documented
public @interface LuceneIndexed
该 LuceneIndexed 正文被用于索引,创立的 GemFire / 的 Geode 上的 GemFire / 的 Geode。GemfirePersistentEntity
GemfirePersistentPropertyLuceneIndexRegion

正文完
 0