Spring Framework Documentation (5.3.10)
Core | IoC Container, Events, Resources, i18n, Validation, Data Binding, Type Conversion, SpEL, AOP. |
1. The IoC Container
1.1. Introduction to the Spring IoC Container and Beans(Spring IoC容器和bean简介)
1.2. Container Overview (容器概览)
1.2.1. Configuration Metadata (配置元数据)
1.2.2. Instantiating a Container(实例化一个容器)
1.2.2.1 Composing XML-based Configuration Metadata(组合基于XML的配置元数据)
1.2.2.2 The Groovy Bean Definition DSL (Groovy Bean定义DSL)
1.2.3. Using the Container (使用容器)
下载此文档精编完整版
No. | 内容 | 下载地址 | 文档内容目录 |
1 | 中英双语精编版 第一部分 | PDF下载 | 内容目录 |
2 | 中英双语精编版 第二部分 | PDF下载 | 内容目录 |
3 | 中文精编版 第一部分 | PDF下载 | 内容目录 |
4 | 中文精编版 第二部分 | PDF下载 | 内容目录 |
更多章节内容,请点击查看: Core Technologies
1.2.2.2 The Groovy Bean Definition DSL (Groovy Bean定义DSL)
As a further example for externalized configuration metadata, bean definitions can also be expressed in Spring’s Groovy Bean Definition DSL, as known from the Grails framework. Typically, such configuration live in a ".groovy" file with the structure shown in the following example:
作为外部化配置元数据(externalized configuration metadata)的另一个示例,也可以在Spring的Groovy bean定义DSL(Groovy Bean Definition DSL)中定义bean,可从Grails框架得知。通常,此类配置位于“.groovy”文件中,其结构如下示例所示:
beans {
dataSource(BasicDataSource) {
driverClassName = "org.hsqldb.jdbcDriver"
url = "jdbc:hsqldb:mem:grailsDB"
username = "sa"
password = ""
settings = [mynew:"setting"]
}
sessionFactory(SessionFactory) {
dataSource = dataSource
}
myService(MyService) {
nestedBean = { AnotherBean bean ->
dataSource = dataSource
}
}
}
This configuration style is largely equivalent to XML bean definitions and even supports Spring’s XML configuration namespaces. It also allows for importing XML bean definition files through an importBeans directive.
这种配置样式在很大程度上等同于XML bean定义,甚至支持Spring的XML配置命名空间(XML configuration namespace)。它还允许通过importBeans 指令(importBeans directive)导入XML bean定义文件。