Sonar “Close Connection” warning workaround.

Tuesday 2009-10-06

When you use Spring and Ibatis and SQLTemplates, you could have code in your project which looks somewhat like this:

Connection connection = DataSourceUtils.getConnection(getDataSource());
...<do connection stuff here>...
DataSourceUtils.releaseConnection(connection, getDataSource());

Sonar will report that you did not close the connection, while in fact, Spring did that for you. You can not just add a “connection.close()” to the code because the whole point of calling “releaseConnection()” is to have Spring handle all the smart stuff on committing, closing, and returning the connection to the pool if needed.

Read the rest of this entry »


Spring SystemPropertyInitializingBean

Wednesday 2008-07-23

When using POI in any of your projects, and the application you’re building is a web application, you probably have it running on a Windows machine. If not, you know all about the struggle with the “headless mode” environment setting to tell the JVM how to handle graphics rendering.

I always like to keep my applications as clean as possible to the users. The system administrator is also a user of the software (during installation at least). So I wanted the application to set the environment properties itself, In this case, I built a nice little Spring bean to handle this. The solution is so simple, that it is almost a brilliant display of what Spring can solve for you. Suddenly, all these environment setting problems turned into a simple Spring configuration problem. Here’s how:

Read the rest of this entry »