mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-05-03 04:19:47 +01:00
aeed3c963b
This commit moves the "Groovy Bean Definition DSL" section to the Groovy page Closes gh-35721
43 lines
1.2 KiB
Plaintext
43 lines
1.2 KiB
Plaintext
[[groovy]]
|
|
= Apache Groovy
|
|
:page-section-summary-toc: 1
|
|
|
|
Groovy is a powerful, optionally typed, and dynamic language, with static-typing and static
|
|
compilation capabilities. It offers a concise syntax and integrates smoothly with any
|
|
existing Java application.
|
|
|
|
[[beans-factory-groovy]]
|
|
== The Groovy Bean Definition DSL
|
|
|
|
The Spring Framework provides a dedicated `ApplicationContext` that supports a Groovy-based
|
|
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:
|
|
|
|
[source,groovy,indent=0,subs="verbatim,quotes"]
|
|
----
|
|
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.
|
|
|