NullPointerException in static factory-method in Spring

For one project, I was trying to test db connection at startup using some method like
public static void testConnection(DataSource ds){...}

which I happily configured in Spring using the factory-method attribute. To my surprise I got NullPointerException in populateMethod of Spring class AbstractAutowireCapableBeanFactory.

The reason for this was, Spring was expecting a object to be returned as it's a factory-method and fatory method will always return some object. Since my use case was to only test the connection and leave it I didnt return anything.

Hope this helps.


Popular posts from this blog

How does HashMap work in Java

Immutable classes

Equals and hashcode method