Spring XML: Invoking setter methods with multiple arguments

In the JavaBeans idea of a perfect world, every mutable field of an object should be mutated with a single-argument setter method. I find this overly restrictive. At any rate, it is a convention that is not universally followed.

When configuring Java beans with Spring XML files, there isn’t an obvious way to deal with setters that take more than one argument. Consider the following method:

public void setTitles(String... titles)
for (String s : titles)

The standard single-arg approach we’re familiar with is:

<bean id="Paul_McCartney" class="com.example.Person">
<propety id="titles" value="Sir"/>

But someone with two titles, like “Rev. Dr. Martin Luther King” isn’t easily handled. This is because the XML attribute “value“, like all XML attributes, cannot be multivalued. Here is the workaround:

<bean id="MLK_JR" class="com.example.Person" />

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject">
        <ref local="MLK_JR"/>
    <property name="targetMethod">
    <property name="arguments">

Credit for this fix due to this question on StackOverflow.


The End of History Illusion

If you think you’re done changing as a person, then consider reading this.

Almost everyone anticipates some measure of vertical growth for themselves (whether it be spiritual, financial, or career). But not as widely expected is horizontal growth: total overhauls of how we act w.r.t. things like personality, attitude, mannerisms, etc.

From the original article published in Science:

People, it seems, regard the present as a watershed moment at which they have finally become the person they will be for the rest of their lives. This “end of history illusion” had practical consequences, leading people to overpay for future opportunities to indulge their current preferences.

E-books have room for improvement

Despite how rapidly technology changes, I want this blog to be useful to people today, and five years from now. The blog format is not (yet) optimized for archived information retrieval, but what is? The book, with table of contents and index, comes close.  But there’s one major flaw: information changes, books don’t.

I don’t care if you can fit more books onto your iPad/Kindle/Nook/tablet than the Library of Congress. E-books are still a largely static product. They are written, published, sold, shipped, and then they die. They just sit there on your reader.

In a recent book announcement, Reg Braithwaite explains his unorthodox publishing approach:

Dead tree books remind me of shrink-wrapped software. Today we love Github and software-as-a-service and continuous deployment and running a business in real time on tight feedback circles. That’s how Linux works, that’s how the web works, that’s how I wanted to publish[…]

So his ebook (it’s a JavaScript functions book) is a living thing, which readers can expect to change. I think it’s a fresh approach.