Spring Tip - PropertyPathFactoryBean
I love the Spring Inversion of Control framework, mainly because every time I think it should do something, I find out that it does. I came across a situation today where I needed to make use of the value of a property as the basis for a setter on a bean. Really, what I needed was a way to copy a property from one bean to a property of another bean. I found that I could use PropertyPathFactoryBean to create a bean with an ID of bean.propertyName and a class of PropertyPathFactoryBean. When that bean was passed in to a setter in the destination object, the typing was seamlessly handled.
Maybe knowing a specific use case would make the power of this all the more obvious. What I was trying to do was set a URL on a business domain bean to a URL derived by calling getURL() on a bean that implemented the Spring Resource interface. I want to keep my domain objects free from any Spring API dependencies, and this approach allowed me to use the power of the Resource interface (and the various provided Spring implementations) without making my code dependent on Spring. All the power, none of the baggage!