Junior — Middle
In what form and how can data be extracted from a Spring bean container?
sobes.tech AI
Answer from AI
In Spring, the bean container is represented by the ApplicationContext interface. To retrieve data (beans) from the container, you can use the getBean() methods.
For example, if you have a bean with a name or class, you can get it like this:
ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
MyBean myBean = context.getBean(MyBean.class);
// or by name
MyBean myBeanByName = (MyBean) context.getBean("myBeanName");
You can also get all beans of a certain type:
Map<String, MyBean> beans = context.getBeansOfType(MyBean.class);
Thus, data from the container is retrieved as objects (bean instances), which can be used in the application.