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 an Eclipse plugin.
1. Install Spring Plugin From Eclipse Marketplace
- Open Eclipse, click the menu item Help —> Eclipse Marketplace.
- Input the keyword Spring IDE in the popup Eclipse Marketplace dialog Find input text box, click the Go button to search the plugin.
- Select the sts ( Spring Tools Suite ) eclipse plugin in the search result list.
- Click the Install button to install it. After a while, it will list all the sts ide required plugins. Click the checkbox to choose them all and click the Confirm button to continue.
- Select the checkbox Accept terms of license agreement in the next wizard, click the Finish button.
- When the sts plugin installation complete, you need to restart eclipse.
- After restart, you can see the eclipse ide Welcome page that shows the Spring IDE link (click to Create a new Spring project) , Spring Tool Suite Dashboard link( click to See the Tool Suite Dashboard) in it.
- If you do not see the eclipse Welcome page, you can click the eclipse Help —> Welcome menu item to show it.
2. Create Spring Java Project
- Open Eclipse, click File —> New —> Project menu item.
- Choose Spring / Spring Legacy Project ” in the popup New Project dialog. Click Next.
- Input Project name and browse to select Location ( project saved directory ) in the Spring Legacy Project wizard dialog.
- Select Simple Projects / Simple Spring Maven in the Templates drop-down list.
- 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.
- If you choose “Simple Java” in step 3, you need to add the jars manually. You can click here to download the latest jars.
- 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.
- 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.
3. Create HelloWorld Java Bean.
- Right click
src/main/java
, click ” New —> Class ” in the popup menu. - Input package name, class name in the popup dialog as below.
- 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.
- Right click
src/main/resources
in left panel, Click ” New —> Others” in popup menu list. - Choose ” Spring Bean Configuration File ” in popup dialog. Click Next.
- Input BeanSettings.xml in configuration file name text box, please note the xml file should be saved in
src/main/resources
directory. Click Next.
- Select related xsd in next dialog. We just select beans xsd.
- Click Next, Finish to close the wizard. You can see BeanSettings.xml has been created in left project tree.
5. Add Java Bean To Bean Configuration File.
- Double click BearSettings.xml file just created.
- Click “New Bean” button in right panel “beans” tab.
- Input bean id in the popup dialog as below. Click Browse button to select HelloWorld class we just created in step 3. Click Next.
- Add following two properties in next dialog.
- Click Finish, Now click Source tab at the bottom, you can see bean definition in xml file.
6. Invoke HelloWorld Java Bean
- Create class
com.dev2qa.example.spring.InvokeHelloWorldBean
. - 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(); }
- Run it, then you can see the below output.
simple maven project does not any thing EXCEPT MANIFEST.MF in file explorer in eclpise in linux mint 19.2 cinnemon. I don’t understand why please, help me to sort out.