Create spring application in Eclipse

In this tutorial, i show you how to create spring application in Eclipse. It’s a simple application of spring framework and help you have a first look about this powerful framework.

Firstly, you should have Eclipse IDE on local computer if you have not yet, please download the lastest version from webapge eclipse.org

To create spring application in Eclipse you should follow to these below steps:

1. Create the Java Project

Now you open Eclipse IDE and go to File menu -> New -> project -> Java Project. Then you should type the project name (for example: springsample) and click Finish button. Now, the springsample project is already created.

2. You should add spring jar files into project

This is simple spring application so you only need five jar files below:

spring-core-4.2.6.RELEASE.jar
spring-beans-4.2.6.RELEASE.jar
spring-context-4.2.6.RELEASE.jar
spring-expression-4.2.6.RELEASE.jar
commons-logging-1.2.jar

To import the jar files in eclipse IDE, right click on your project -> Build Path -> Add external archives -> select all the above jar files in a directory -> finish.

3. Create Java class

In this tutorial, you are creating the Fruit class have name and produceby property. To create the java class, on the project explorer, right click on src -> New -> class -> Type the class name Fruit -> finish. Simply you implement this class as below:

4. Create the application context xml file for spring framework application

It’s easy to create the xml file by clicking on src -> New -> file -> type file name such as applicationContext.xml -> finish. You should configure a bean for the class Fruit as below:

This is a way to define the bean for the Fruit class. The values of name and produceby properties will be assigned for properties of the Fruit class by the IOC container.

5. Create the SpringSample class

In this SpringSample class you are getting the object of Fruit class from Spring IOC container using the getBean() method of ApplicationContext.

Run it then you will get the result as below.

Finally, you are familiar to the tutorial create spring application in Eclipse. In the next time, hope that you could create your own spring application.

Happy learing!

Leave a Comment

*

Please share it if you found this useful
Hide Buttons