Sunday, 29 July 2012

Upgrading to Spring 3.1

A few days ago I thought that it was about time to upgrade my sample code to Spring 3.1, after all it’s been around for a respectable amount of time and has a couple of bug fix releases.

Upgrading to Spring 3.1 is very simple of upgrading your Maven version number and rebuilding, something like this:


...for every Spring dependency.

After recompiling you’ll probably find a whole bunch of newly deprecated classes such as XmlBeanFactory, which has been deprecated in favour of DefaultListableBeanFactory so,

    Resource resource = new ClassPathResource("example2.xml");
return new XmlBeanFactory(resource);


    Resource resource = new ClassPathResource("example2.xml");

    DefaultListableBeanFactory beanFactory =
new DefaultListableBeanFactory();
    BeanDefinitionReader reader =
new XmlBeanDefinitionReader(beanFactory);

For a full list of deprecated classes

The next thing to do is option, but a good idea is to change your Spring XML headers from 3.0 to 3.1 so that the XML schema’s referenced end in -3.1.xsd. For example:


The easiest way of doing this is to use eclipse’s global replace to replace to change -3.0.xsd with -3.1.xsd, but have a quick check first before your do this...

The reason for updating your schema’s is to take advantage of Spring’s new features.

And that's about it - a very short and simple blog, but then upgrading was painless. If you're still using Spring 2.x and want to upgrade to 3 then take a look at this older blog.

No comments: