If you take a look at the article that was referred to when we prepared this sample
(www.pleus.net/articles/grules/grules.pdf), it also shows how the rule parameter can be externalized
into an Excel file, so users can prepare and update the parameter file by themselves.
Of course, this rule is a simple one, but you should have an idea of how a scripting language like
Groovy can help supplement Spring-based Java EE applications in specific areas like rule engine with
DSL.
You may be asking, "Is it possible to go one step further by storing the rule into the database and
then have Spring's refreshable bean feature detect the change from the database?" This can help further
simplify the maintenance of rule by providing a frontend for users (or administrator) to update the rule
into the database on the fly, instead of uploading the file. Actually, there is a JIRA issue in the Spring
Framework that discusses this (https://jira.springsource.org/browse/SPR-5106). Stay tuned with this
feature. In the meantime, providing a user frontend to upload the rule class is also a workable solution.
Of course, extreme care should be taken in this case, and the rule should be tested thoroughly before you
upload it to the production environment.
Summary
In this chapter, we covered how to use scripting languages in Java applications and demonstrated how
the Spring Framework's support of scripting language can help provide dynamic behavior to the
application.
First we discussed JSR-223, the Scripting for the Java Platform API, which was built into JSE 6 and
supports the execution of JavaScript out of the box. Then, we introduced Groovy, a popular scripting
language within the Java developer communities. We also demonstrated some of its main features when
compared to the traditional Java language.
Finally, we discussed the support of scripting languages in the Spring Framework. We saw it in
action by designing and implementing a very simple rule engine using Groovy's DSL support. We also
discussed how the rule can be modified and have the Spring Framework pick up the changes
automatically by using its refreshable bean feature, without the need to compile, package, and deploy
the application.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home