Upgrading A Spring JDBC Project To Spring Version 3.2.2


I recently updated a Java project that uses Spring JDBC from Spring version 3.1.0.RELEASE to Spring version 3.2.2.RELEASE.  To get everything to work correctly I had to make a few changes that I thought others might find helpful to know about.

Change Maven Dependencies

In my project’s pom.xml I had to add a separate dependency for spring-context.  In Spring version 3.1.0.RELEASE spring-jdbc had a transitive dependency to spring-context.  In Spring version 3.2.2.RELEASE there is no longer a transitive dependency in spring-jdbc to spring-context.  So you may need to add a separate dependency node in your pom.xml for spring-context.

Replace Deprecated Methods

If your Spring JDBC project uses class NamedParameterJdbcTemplate then you may need to check if the methods of that class you are calling are now deprecated and should be replaced.  I was using method queryForInt of class NamedParameterJdbcTemplate.  After upgrading to Spring version 3.2.2.RELEASE Eclipse provided me with a friendly deprecated warning. 

Checking the JavaDoc for the NamedParameterJdbcOperations interface (which NamedParameterJdbcTemplate implements) I found that queryForInt should be replaced by queryForObject.  There are versions of the queryForObject method that have a parameter which specifies the class type to return.

So I replaced:

queryForInt("select count(0) from personTbl")


queryForObject("select count(0) from personTbl", Integer.class)

There are some other deprecated methods so you may want to review the JavaDocs for Spring JDBC classes used in your project or the list of deprecated items.

There is an example Maven project in my GitHub repository, SpringJDBCExamplesEmbeddedDatabase, that demonstrates using Spring JDBC with Spring version 3.2.2.RELEASE. In that project's README.txt file are instructions for how to build and run the application along with the steps I had to take when upgrading the project to Spring version 3.1 and then to 3.2.2.

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version Contact Blog Owner