91-9990449935 0120-4256464 |
Creating spring application in Eclipse IDEHere, we are going to create a simple application of spring framework using eclipse IDE. Let's see the simple steps to create the spring application in Eclipse IDE.
Steps to create spring application in Eclipse IDELet's see the 5 steps to create the first spring application using eclipse IDE. 1) Create the Java ProjectGo to File menu - New - project - Java Project. Write the project name e.g. firstspring - Finish. Now the java project is created. 2) Add spring jar filesThere are mainly three jar files required to run this application.
For the future use, You can download the required jar files for spring core application. download the core jar files for spring download the all jar files for spring including aop, mvc, j2ee, remoting, oxm, etc. To run this example, you need to load only spring core jar files. To load the jar files in eclipse IDE, Right click on your project - Build Path - Add external archives - select all the required jar files - finish.. 3) Create Java classIn such case, we are simply creating the Student class have name property. The name of the student will be provided by the xml file. It is just a simple example not the actual use of spring. We will see the actual use in Dependency Injection chapter. To create the java class, Right click on src - New - class - Write the class name e.g. Student - finish. Write the following code: This is simple bean class, containing only one property name with its getters and setters method. This class contains one extra method named displayInfo() that prints the student name by the hello message. 4) Create the xml fileTo create the xml file click on src - new - file - give the file name such as applicationContext.xml - finish. Open the applicationContext.xml file, and write the following code: The bean element is used to define the bean for the given class. The property subelement of bean specifies the property of the Student class named name. The value specified in the property element will be set in the Student class object by the IOC container. 5) Create the test classCreate the java class e.g. Test. Here we are getting the object of Student class from the IOC container using the getBean() method of BeanFactory. Let's see the code of test class. Now run this class. You will get the output Hello: Vimal Jaiswal.
Next TopicIOC Container
|