Java Reference
In-Depth Information
def "transfer funds works"() {
when:
service.transferFunds(0,1,25.0)
then:
service.getAccountBalance(0) ==
old(service.getAccountBalance(0)) - 25.0
service.getAccountBalance(1) ==
old(service.getAccountBalance(1)) + 25.0
}
}
As before, the annotations let the Spock test work with Spring's test framework, which
caches the application context. I used the old operation from Spock to check changes in
the account balance after a deposit or withdrawal. No other additions are needed to use
Spock with the Spring test context.
This application, though simple, illustrates a lot of Spring's capabilities, from declarative
transactionmanagementtoautowiringtosimplifiedJDBCcodingtoeffectivetesting.From
Spring's point of view, Groovy beans are just bytecodes by another name. As long as the
groovy-allJARfileisintheclasspath,SpringisquitehappytousebeanswritteninGroovy.
Spring manages beans from Groovy as easily as it manages beans from Java. There are
special capabilities that Spring offers beans from dynamic languages, though. I'll illustrate
them in the next sections, beginning with beans that can be modified in a running system.
7.2. Refreshable beans
Since version 2.0, Spring has provided special capabilities for beans from dynamic lan-
guages like Groovy. One particularly interesting, if potentially dangerous, option is to de-
ploy what are known as refreshable beans.
For refreshable beans, rather than compile classes as usual, you deploy the actual source
code and tell Spring where to find it and how often to check to see if it has changed. Spring
checks the source code at the end of each refresh interval, and if the file has been modified
it reloads the bean. This gives you the opportunity to change deployed classes even while
the system is still running. [ 3 ]
Search WWH ::




Custom Search