Saturday, March 15, 2008

Wiring up Spring with JRuby

I'd like to use Spring Framework for Java development but I hate its XML configuration because the configuration is just too verbose and awkward. So what to do? Springy to the rescue! It lets you use a simple DSL based on JRuby to wire up your Spring context.

So instead of this:

<bean id="bean3" class="springy.beans.Bean3">
<constructor-arg value="${vic}">
<constructor-arg ref="bean2">
<property name="aProperty">
<list>
<ref bean="bean1"/>
<value>A String</value>
</list>
</property>
</bean>

I can use Springy's DSL:

bean :bean3, "springy.beans.Bean3" do |b|
b.new(vic, :bean2)
b.aProperty = [ :bean1, "A String" ]
end

No comments: