0

我正在使用 Spring Data 和 Gemfire 开发数据服务。有注释

@Region("<region name>")

指定 POJO 将存储在哪个 Gemfire 区域。

它需要配置的 Gemfire 区域的名称。我觉得硬编码区域名称是一种不好的做法,因为 Gemfire 集群将由一个单独的团队管理,我相信区域名称应该是完全可配置的。

有没有更好的做法来避免对区域名称进行硬编码?

4

3 回答 3

1

The region name must be shared by all processes that access the region. This is analogous to a table name in a relational database. In this sense, it is no different than JPA or Hibernate annotations that declare the table name in which the POJO will be stored. IIRC, using Spring Data Repositories, if @Region is not present it will get it from the class name. But either way, the corresponding region must exist. If your application is a client to the GemFire grid, you must also configure a client region with the same name as the corresponding region on the server. If it's a peer than you must create the region (either a partition or a replica). These things may be done with Spring configuration or native GemFire configuration, but in any event, the shared region name must be known in advance and if it changes, it must change everywhere.

于 2014-02-06T13:58:39.447 回答
1

可以使用 Spring Expression Language 来注入 Region 的名称吗?

我们将一个基于 XML 文件的配置 bean 中的值注入到 @Value 注释中,例如:

@Value("#{config.dataSourceConfig.dbMainUsername}")

其中“config”是配置 bean 的名称。

不确定这是否适用于所有注释...

于 2014-02-20T16:52:02.907 回答
0

一般来说,我认为在应用程序域对象的@Region 注释中指定区域的名称/路径不一定是不好的做法;它当然要明确得多。

但是,我可以理解使这些东西可配置的必要性,也许当您从 1 个 env(例如 DEV)提升到另一个(例如 PROD)时。因此,请参阅最近的变化...

SGF-261 - 允许将应用程序域对象/实体持久保存到 GemFire 缓存中的多个区域

除了这个提议,未来的变化......

SGF-262

于 2014-03-06T23:56:17.657 回答