保持领先
VMware 提供培训和认证,助您快速进步。
了解更多亲爱的 Spring 社区!
Spring Cloud GCP 是一套 Spring Boot starter,旨在帮助您直接从 Spring Boot 利用 Google Cloud Platform 的托管服务,使您能够将 Spring Messaging 用于 Cloud Pub/Sub,将 Spring Resource 用于 Cloud Storage,将 Spring Cloud Sleuth 用于 Stackdriver Trace,将 Spring Data 与 Cloud SQL 结合使用,等等。
我们刚刚发布了 Spring Cloud GCP 1.0.0.M3
。查看自上一个 Milestone 2 以来的新特性!
Spring Cloud GCP 1.0.0.M3
现在已更新,可与 Spring Boot 2.0.1.RELEASE
和 Spring Cloud Finchley.M9
一起使用。
要使用 Spring Cloud GCP 1.0.0.M3
,只需在您的 Spring Boot 2.0
项目中导入 BOM 即可。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-dependencies</artifactId>
<version>1.0.0.M3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
您现在可以在 Spring Initializr 中找到 Spring Cloud GCP!前往 http://start.spring.io/ 并查找与 "GCP" 相关的 starter。
例如,要使用 Cloud Pub/Sub 进行消息传递,只需在 Initializr 中添加 GCP Messaging 依赖项。这个 starter 还包含 Spring Integration 通道适配器,以及 Spring Cloud Stream Pub/Sub binder。
目前,Initializr 菜单中仅包含基础支持、消息传递和存储相关的 starter。请参阅 Spring Cloud GCP 参考文档以添加其他 starter。我们正在努力将更多内容添加到 Initializr。
您现在可以构建由 Google Cloud Spanner 支持的多区域 Spring Boot 应用程序,Google Cloud Spanner 是一种全球分布、强一致性的关系型数据库。借助 Spring Data Spanner,您现在可以为 POJO 添加注解,以实现对象到 Spanner 表的映射。它支持:
Spanner 事务
分页和排序 Repository
REST Repository
通过方法名约定、注解和命名查询进行查询!
@Table(name = "traders") public class Trader { @PrimaryKey @Column(name = "trader_id") String traderId;
String firstName;
String lastName;
}
public interface TraderRepository extends PagingAndSortingRepository<Trader, String> { }
如果您正在使用 Pivotal Cloud Foundry 和 Google Cloud Platform Service Broker,Spring Boot GCP Starter 可以自动使用 GCP Service Broker 的绑定和凭据来配置您的应用程序。支持以下服务:
Cloud Storage
Cloud Pub/Sub
Cloud Spanner
Stackdriver Trace
如果您不熟悉在 Cloud Foundry 上使用 Spring Boot,请查看 Spring Boot Cloud Foundry 部署文档。
例如,您可以通过 Service Broker 预配和绑定 Stackdriver Trace 服务凭据:
$ cf create-service google-stackdriver-trace default mytrace $ cf bind-service myapp mytrace
在您的应用程序中,添加 Spring Cloud GCP Trace starter:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-trace</artifactId>
</dependency>
当您将应用程序部署到 PCF 并进行此服务绑定时,starter 将自动从 VCAP_SERVICES
环境变量中读取配置。Spring Cloud Trace starter 将自动把分布式跟踪数据转发到 Stackdriver Trace。
$ cf push myapp -p path/to/my.jar
Stackdriver Trace 是 Stackdriver 应用性能管理 (APM) 工具的一部分。请从 Stackdriver APM 公告博客了解更多信息。
查看 Spring Cloud GCP GitHub 仓库中的代码示例,阅读 Spring Cloud GCP 参考文档了解更多详细信息,并通过代码实验室进行实践。最重要的是,请告诉我们您的反馈并报告任何问题。
来自 Spring Cloud GCP 团队