I’m trying to convert a simple Spring 2.5 hello world project (from Spring Recipes) to 3.0. For starters, I created a Simple Spring Utility Project (from the Spring Template Project option for new projects).
I’ve copied the source code into the “src/main/java/com.apress.springrecipes.hello” package of the 3.0 project. There, the bean configuration file is at “src/main/resources/META-INF/spring/app-context.xml”. However, the 2.5 hello world calls the file “beans.xml” and it’s created in the root path of the project. The code for the Main class looks like this:
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext("beans.xml");
HelloWorld helloWorld = (HelloWorld) context.getBean("helloWorld");
helloWorld.hello();
}
How would I change this to find the new app-context.xml?
I’d add the
src/main/resources/META-INF/springdirectory to theCLASSPATHand then change the code like this:That change has nothing to do with Spring version; it requires that you understand what your CLASSPATH is and where Spring will look to load application context XML files.
You should understand how you can leverage annotations for auto wiring.
You should read about the new features in Spring 3.1.
You should change your Spring application contexts to point to the new version 3.0 .xsd and namespace.
You need the 3.1 JARs, of course.