编写Groovy脚本并运行应用程序

Spring Cloud CLI 支持大多数的 Spring Cloud 集成式(声明式) 特性,例如 @Enable* 注解类。例如, 这里是完全功能的 Eureka 服务器spring-doc.cadn.net.cn

app.groovy
@EnableEurekaServer
class Eureka {}

您可以通过以下方式从命令行运行spring-doc.cadn.net.cn

$ spring run app.groovy

要包含其他依赖项,通常只需添加适当的启用功能注释,例如@EnableConfigServer@EnableOAuth2Sso@EnableEurekaClient。要手动包含一个依赖项,您可以使用一个@Grab,使用特殊的“Spring Boot”短样式坐标,即只需 artifactId(不需要组或版本信息),例如设置管理事件从 Spring CLoud Bus 的 AMQP 客户端应用程序:spring-doc.cadn.net.cn

app.groovy
@Grab('spring-cloud-starter-bus-amqp')
@RestController
class Service {
  @RequestMapping('/')
  def home() { [message: 'Hello'] }
}