How To Install Spring IDE Eclipse Plugin

Spring IDE is a useful graphical development tool. It can make Spring application development easy. This article will show you how to install it as a Eclipse plugin.
 1. Install Spring Plugin From Eclipse Marketplace

  1. Open Eclipse, click ” Help —> Eclipse Marketplace”.
    help eclipse marketplace menu item
  2. Input “Spring IDE” in popup dialog, Click Enter key.
    search spring ide in eclipse marketplace
  3. Click Install button to install. After some time, all IDE related plugin list out. Choose them all. Click Confirm button.
    install spring ide eclipse plugin
  4. Choose “Accept terms of licence agreement”, click Finish button.
  5. When plugin installation complete, you need to restart Eclipse.
  6. After restart, you can see below picture which means installation success.
    spring eclipse plugin installation successful

2. Create Spring Java Project

  1. Open Eclipse, click ” File —> New —> Project ” menu item.
  2. Choose ” Spring Legacy Project ” in popup dialog. Click Next.
    choose spring legacy project
  3. Input project settings like below.
    spring project settings
  4. After click Finish button, you can see the project listed in Eclipse left panel. Because we choose “Simple Spring Maven” in step 3. So all Spring related jars has been added in the project.
    spring project in eclipse left panel
  5. If you choose “Simple Java” in step 3, you need to add the jars manually. You can click here to download the latest jars.
    download spring dependency jars page
  6. After download, unzip it to a local folder. Then add related jars into java project. You can read Spring Hello World Example Use Maven And Eclipse to learn how to add the jars to project.
  7. Spring use commons-logging by default, so you need to click here to download commons-logging jar lib file. Then add it to project build path.
    commons logging download page

3. Create HelloWorld Java Bean.

  1. Right click src/main/java, click ” New —> Class ” in the popup menu.
  2. Input package name, class name in the popup dialog as below.
    create hello world java bean
  3. Input below java code in HelloWorld.java. Please note all the private instance field should has a set and get method.
    public class HelloWorld {
    	
    	private String firstName;
    	
    	private String lastName;
    
    	public String getFirstName() {
    		return firstName;
    	}
    
    	public void setFirstName(String firstName) {
    		this.firstName = firstName;
    	}
    
    	public String getLastName() {
    		return lastName;
    	}
    
    	public void setLastName(String lastName) {
    		this.lastName = lastName;
    	}
    	
    	public void sayHello()
    	{
    		System.out.println("Hello " + this.getFirstName() + " " + this.getLastName());
    	}
    }
    

4. Create Spring Bean Configuration Xml File.

  1. Right click src/main/resources in left panel, Click ” New —> Others” in popup menu list.
  2. Choose ” Spring Bean Configuration File ” in popup dialog. Click Next.
    create spring bean configuration file
  3. Input BeanSettings.xml in configuration file name text box, please note the xml file should be saved in src/main/resources directory. Click Next.
    input spring bean configuration file name
  4. Select related xsd in next dialog. We just select beans xsd.
    spring bean configuration file xsd selection
  5. Click Next, Finish to close the wizard. You can see BeanSettings.xml has been created in left project tree.
    BeanSettings.xml file craeted in left project tree panel
READ :   H2 Database Tutorial

5. Add Java Bean To Bean Configuration File.

  1. Double click BearSettings.xml file just created.
  2. Click “New Bean” button in right panel “beans” tab.
    add new java bean in spring configuration xml file
  3. Input bean id in the popup dialog as below. Click Browse button to select HelloWorld class we just created in step 3. Click Next.
    input bean id and classselect spring bean class
  4. Add following two properties in next dialog.
    add spring bean properties
  5. Click Finish, Now click Source tab at the bottom, you can see bean definition in xml file.
    bean definiton in xml file

6. Invoke HelloWorld Java Bean

  1. Create class com.dev2qa.example.spring.InvokeHelloWorldBean.
  2. Add below java code in it.
    	public static void main(String[] args) {
        	/* Initiate Spring application context. */
    		ApplicationContext springAppContext = new ClassPathXmlApplicationContext("BeanSettings.xml");
    
    		/* Get HelloWorldBean by id. */
    		HelloWorld helloWorldBean = (HelloWorld) springAppContext.getBean("helloWorldBean");
    		
    		/* Set bean field value. */
    		helloWorldBean.setFirstName("Lucky");
    		
    		/* Call bean method. */
    		helloWorldBean.sayHello();
    	}
    
  3. Run it, then you can see below output.
    spring helloworld java bean sayHello method output

7. Source Code

  1. Download “SpringExampleProject.zip” SpringExampleProject.zip – Downloaded 53 times – 13 KB

(Visited 486 times, 5 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.