Checking a bean's health

Sometimes the little details get overlooked. While I'm working on my book about Acegi Security I read a lot of its source code and that's always a refreshing learning experience. In fact I'd like to recommend anyone to take advantage of open source and take it literally: read the source. It educates and stimulates.

What did I find? Nothing big, but still something I had overlooked in a past project when I wanted to make sure that beans that were vital to the system have been properly initialized. In Spring there is the InitializingBean interface, which defines the afterPropertiesSet() method. Spring will call this method on all beans implementing this interface after it has set the bean's properties.

Now you can use Spring's Assert class to perform checks and have an exception thrown, if something is wrong. It's all built-in and free.