Skip to Content

Based on the learning from An example of building Java project using Maven we can now use Maven to do more practical task.

I plan to create a Hello World application based on Spring framework. Instead of manually downloading Spring framework jar files and configured the usage of those jars into my Java project, I can now leverage Maven to make the whole process run automatically.

Install m2e – Maven integration plugin for Eclipse:


And then create a new Java project, and you can easily convert this project to a Maven project via context menu:


Once converted, you can then declare the dependency by clicking pom.xml and choose “Maven->Add Dependency” from context menu:


Enter group id, artifact id and version accordingly. Once done, the XML content should look as below:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="" xmlns:xsi="" 

Trigger a build via mvn clean install, and Maven will automatically download the necessary jars of Spring framework and store them to .m2 folder.


Now we can start programming in Spring.

My project has the following hierarchy:


All missing import could be correctly parsed and easily fixed now.


If you would like to do some debugging on Spring framework source code, you can also download the related source code very easily via “Maven->Download Sources”.


After that you could just set a breakpoint on the constructor of HelloWorld class and then study how Spring instantiates the instance of this class configured in beans.xml via reflection:


The source code of files used in the project

public class HelloWorld {
    private String message;
    public void setMessage(String message){
       this.message  = message;
    public HelloWorld(){
     System.out.println("in constructor");
    public void getMessage(){
       System.out.println("Your Message : " + message);

import org.springframework.context.ApplicationContext;
public class MavenSandbox {
public static void main(String[] args) {
  ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
  HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
public String hello(){
  return "Hello world";

import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class MavenSandboxTest {
public void test() {
  MavenSandbox tool = new MavenSandbox();
  assertEquals(tool.hello(),"Hello world");


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
   <bean id="helloWorld" class="">
       <property name="message" value="Hello World!"/>
To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply