spring core example with maven

In this post, I am giving idea, how to create spring-core project with maven,
Before creating maven project maven should install in your system.If you not installed maven please go through this how to install maven

Step 1 : Go to Eclipse File----> New ----> Other ---->Maven Project.
Step 2:  Now it will open a window as shown in the below 


Step 3: Now as showed in the screen select the check boxes and then click Next
Step 4: Now it will show next wizard as shown in the following screen.

Step 5: Enter the Group Id and Artifact Id and then click finish.
Step 6:  After Creating the Maven Project you can see the folder structure like below.


Step 7 : Now Open the pom.xml file and after version tag, add maven depenedencies as showed in the following code.
0.0.1-SNAPSHOT
   
  
   org.springframework
   spring-core
   ${spring.version}
  
  
   org.springframework
   spring-context
   ${spring.version}
  
 
 
 
  3.2.3.RELEASE
 

Step 8: Now Save the pom.xml, then right click on the project--->maven---> update project, now the spring related jar files will come under maven dependencies.

Step 9 : Create Spring bean configuration file under src/main/resources, the name is any thing.xml here my file name is applicationContext.xml



 
 
 
 
  
 

Step 10: Create a spring bean class now, as shown in the below.

package com.sudheer.spring;

public class SpringWorld {
 private String name;

 public String getName() {
  return name;
 }

 public void setName(String name) {
  this.name = name;
 }
 
 public void welcome(){
  
  System.out.println(name+" Welcome to spring world");
 }
}

Step 11: Create a spring client application class now, as shown in the below:
package com.sudheer.spring;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class CleintApplication {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  
  ApplicationContext context= new ClassPathXmlApplicationContext("applicationContext.xml");
  
  SpringWorld obj=(SpringWorld)context.getBean("springWorld");
  
  obj.welcome();
  
 }

}

Step 12: Now run spring client application. :)

Search This Blog

All the rights are reserved to this blog is belongs to me only.. Powered by Blogger.