Update 56. Developing application with the Groovy beans DSL.md
parent
1c9be556ca
commit
9c73616634
|
@ -0,0 +1,26 @@
|
|||
### 56. 使用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放到一个单独的文件中。
|
Loading…
Reference in New Issue