> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/vii.-spring-boot-cli/65.-developing-application-with-the-groovy-beans-dsl.md).

# 65. 使用Groovy beans DSL开发应用

Spring框架4.0版本对`beans{}`"DSL"（借鉴自[Grails](http://grails.org/)）提供原生支持，你可以使用相同格式在Groovy应用程序脚本中嵌入bean定义。有时这是引入外部特性的很好方式，比如中间件声明，例如：

```java
@Configuration
class Application implements CommandLineRunner {

    @Autowired
    SharedService service

    @Override
    void run(String... args) {
        println service.message
    }

}

import my.company.SharedService

beans {
    service(SharedService) {
        message = "Hello World"
    }
}
```

你可以使用`beans{}`混合位于相同文件的类声明，只要它们都处于顶级，或如果喜欢的话，你可以将beans DSL放到一个单独的文件中。
