
Originally Posted by
Ben Alex
Just a few quick points:
1. Spring's IoC container is not tied to XML. There are various bean definition readers, such as the properties reader. XML is the most popular, but Spring != XML.
The point is that at the moment there are no serious alternatives. I heard something about groovy integration in the beginning, but that has been some time.
2. There have been recent improvements in the XML syntax. It's now less verbose. Awareness of current features like <property name="foo" ref="fooService"/> and inner beans significantly reduce XML.
Yes.. but that doesn`t make XML less verbose. If I write config files, I have the option:
-create larger beans (with a lot of inner beans) so they don`t polute config files and only have a meaning in a specific bean
-create a lot of smaller beans.. but now the configuration file(s) gets polluted with beans that are only used in a specifc context (they are outside of their scope).
If I remove the XML syntax and introduce a domain language, I can guarantee that the config files will be a lot shorter.
[edit]
Here is an example of the original spring configuration.
Code:
<bean id="indexUpdaterScheduler"
class="org.jph.spring.scheduling.concurrent.ScheduledThreadPoolExecutorFactoryBean">
<property name="threadFactory">
<bean class="org.jph.concurrent.StdThreadFactory">
<constructor-arg index="0" value="2"/>
<constructor-arg index="1" value="indexUpdater"/>
</bean>
</property>
<property name="scheduledWithFixedDelayRunnables">
<list>
<bean class="org.jph.spring.scheduling.concurrent.ScheduledWithFixedDelayRunnable">
<property name="runnable">
<bean class="org.jph.spring.scheduling.MethodInvokeSequenceRunnable">
<property name="methodInvokerList">
<list>
<bean class="org.springframework.util.MethodInvoker">
<property name="targetObject" ref="indexUpdater-image"/>
<property name="targetMethod" value="process"/>
</bean>
<bean class="org.springframework.util.MethodInvoker">
<property name="targetObject" ref="indexReaderProviderService-image"/>
<property name="targetMethod" value="refresh"/>
</bean>
<bean class="org.springframework.util.MethodInvoker">
<property name="targetObject" ref="indexUpdater-movie"/>
<property name="targetMethod" value="process"/>
</bean>
<bean class="org.springframework.util.MethodInvoker">
<property name="targetObject" ref="indexReaderProviderService-movie"/>
<property name="targetMethod" value="refresh"/>
</bean>
</list>
</property>
</bean>
</property>
<property name="initialDelay" value="5"/>
<property name="delay" value="30"/>
<property name="timeUnit" ref="java.util.concurrent.TimeUnit.SECONDS"/>
</bean>
<bean class="org.jph.spring.scheduling.concurrent.ScheduledWithFixedDelayRunnable">
<property name="runnable">
<bean class="org.jph.spring.scheduling.MethodInvokeSequenceRunnable">
<property name="methodInvokerList">
<list>
<bean class="org.springframework.util.MethodInvoker">
<property name="targetObject" ref="indexOptimizer-image"/>
<property name="targetMethod" value="optimize"/>
</bean>
<bean class="org.springframework.util.MethodInvoker">
<property name="targetObject" ref="indexReaderProviderService-image"/>
<property name="targetMethod" value="refresh"/>
</bean>
<bean class="org.springframework.util.MethodInvoker">
<property name="targetObject" ref="indexOptimizer-movie"/>
<property name="targetMethod" value="optimize"/>
</bean>
<bean class="org.springframework.util.MethodInvoker">
<property name="targetObject" ref="indexReaderProviderService-movie"/>
<property name="targetMethod" value="refresh"/>
</bean>
</list>
</property>
</bean>
</property>
<property name="initialDelay" value="14400"/>
<property name="delay" value="86400"/>
<property name="timeUnit" ref="java.util.concurrent.TimeUnit.SECONDS"/>
</bean>
</list>
</property>
</bean>
here is the same bean written in a domain language
Code:
import org.jph.spring.scheduling.concurrent.*;
import org.jph.concurrent.*;
import java.util.concurrent.TimeUnit.*;
bean id(indexUpdaterScheduler) class=ScheduledThreadPoolExecutorFactoryBean{
threadFactory bean class=StdThreadFactory(value(2),value(indexUpdater));
scheduledWithFixedDelayRunnables list[
//index-updaters scheduling
bean class= ScheduledWithFixedDelayRunnable{
runnable = bean class=MethodInvokeSequenceRunnable{
bean class=MethodInvoker {
targetObject ref(ndexUpdater-image)
method value(process)}
bean class=MethodInvoker {
targetObject ref(indexReaderProviderService-image)
method value(refresh)}
bean class=MethodInvoker {
targetObject ref(indexUpdater-movie)
method value(process)}
bean class=MethodInvoker {
targetObject ref(indexReaderProviderService-movie)
method = value(refresh)}
}
initialDelay value(10)
delay value(30)
timeUnit ref(TimeUnit.SECONDS)
}
//optimize scheduling
bean class= ScheduledWithFixedDelayRunnable{
runnable bean class=MethodInvokeSequenceRunnable{
bean class=MethodInvoker {
targetObject ref(indexOptimizer-image)
method value(optimize)}
bean class=MethodInvoker {
targetObject ref(indexReaderProviderService-image)
method value(refresh)}
bean class=MethodInvoker {
targetObject ref(indexOptimizer-movie)
method value(optimize)}
bean class=MethodInvoker {
targetObject ref(indexReaderProviderService-movie)
method value(refresh)}
}
initialDelay value(14400)
delay value(86400)
timeUnit ref(TimeUnit.SECONDS)
}
]
}
The syntax can be improved. Instead of using bean class='Foo' it would be more natural to say: new Foo. But this is only an attempt to create a better and clearer syntax.