Skip to content

Commit ac7a117

Browse files
author
DESKTOP-BL7US23\architbiet
committed
retriving bean from config file = (context) = (container)
1 parent 81a6306 commit ac7a117

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.luv2code.springdemo;
2+
3+
import org.springframework.context.support.ClassPathXmlApplicationContext;
4+
5+
public class AnnotationDemoApp {
6+
7+
public static void main(String[] args) {
8+
9+
// Read the spring config file
10+
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
11+
12+
// Retrieve the bean from Spring container
13+
Coach coach = context.getBean("thatSillyCoach", Coach.class);
14+
15+
// Call methods on the bean
16+
System.out.println(coach.getDailyWorkout());
17+
18+
// Close the context
19+
context.close();
20+
}
21+
}

0 commit comments

Comments
 (0)