Updating from spring 3.1 to spring 4.3

Recently I have been working on an application that was using Java 7 and Spring 3.1.1.  And we upgraded from Java 7 to Java 8.  And once we had Java 8 installed, all the spring beans seemed to work fine with spring 3.1.1. But once we started to use java 8 features in Spring beans, the code would compile fine and only start to throw exceptions on server startup. So we were forced to upgrade to Spring 4.3.5 (latest stable release as of now).

The migration was very much two lines of code change for us. One we to change the version in pom.xml and other one was a removed method in org.springframework.jdbc.core.JdbcTemplate

queryForInt()/queryForLong() Removed in spring 4.x

queryForInt()/queryForLong() were deprecated in spring 3.2.2  and have been removed from spring 4.x.

So the solution to this issue was to replace it with
 queryForObject(String sql,Class<T> requiredType)

Old :

Integer i = queryForInt(sql)

New:

Integer i = queryForObject(sql, Integer.class);

 

Summary

The upgrade was only a two line changes and went very smoothly. And all the spring related stuff seems to work fine after the upgrade.

 

Like this post? Don’t forget to share it!

Leave a Reply

Your email address will not be published. Required fields are marked *