5.15.2 Spring Example in Eclipse
5.15.2 Spring Example in Eclipse
com/example-of-spring-application-in-eclipse
For the future use, You can download the required jar files for spring core application. download the core jar
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..
1 of 3 06-06-2024, 11:58
Spring Example in Eclipse - javatpoint https://www.javatpoint.com/example-of-spring-application-in-eclipse
1. package com.javatpoint;
2.
3. public class Student {
4. private String name;
5.
6. public String getName() {
7. return name;
8. }
9.
10. public void setName(String name) {
11. this.name = name;
12. }
13.
14. public void displayInfo(){
15. System.out.println("Hello: "+name);
16. }
17. }
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.
2 of 3 06-06-2024, 11:58
Spring Example in Eclipse - javatpoint https://www.javatpoint.com/example-of-spring-application-in-eclipse
7.
8. public class Test {
9. public static void main(String[] args) {
10. Resource resource=new ClassPathResource("applicationContext.xml");
11. BeanFactory factory=new XmlBeanFactory(resource);
12.
13. Student student=(Student)factory.getBean("studentbean");
14. student.displayInfo();
15. }
16. }
Now run this class. You will get the output Hello: Vimal Jaiswal.
3 of 3 06-06-2024, 11:58