81. 编写 Groovy 脚本和 Running Applications
Spring Cloud CLI 支持大多数 Spring Cloud 声明 features,例如@Enable*
class of annotations。例如,这是一个功能齐全的 Eureka 服务器
app.groovy.
@EnableEurekaServer
class Eureka {}
您可以从命令 line 中运行 run
$ spring run app.groovy
要包含其他依赖项,通常只需添加适当的 feature-enabling annotation,e.g 即可。 @EnableConfigServer
,@EnableOAuth2Sso
或@EnableEurekaClient
。要手动包含依赖项,可以使用@Grab
和特殊的“Spring Boot”短样式_art ,i.e。只有 artifact ID(不需要 group 或 version 信息),e.g. 设置一个 client 应用程序,以便从 Spring CLoud Bus 中监听 AMQP 的 management events:
app.groovy.
@Grab('spring-cloud-starter-bus-amqp')
@RestController
class Service {
@RequestMapping('/')
def home() { [message: 'Hello'] }
}