How many types of container present in Spring | BeanFactory vs Application conext | Spring Question

Описание к видео How many types of container present in Spring | BeanFactory vs Application conext | Spring Question

#SpringCore #Container #BeanFactory #Vs #ApplicationContext

► SUBSCRIBE & LIKE!!

► Important Information and code guide available bottom of the Description section

► Official Email Id: [email protected]
► Download the sample java microservice application :
https://github.com/admindebu/Spring-D...
► Follow on Facebook:   / techtalkdebu  
► Follow on LinkedIn:   / debu-paul  

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
► Here is our amazing playlist for Core Java, Spring MVC/Boot, Git and Microservice
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Core Java :: https://www.youtube.com/watch?v=IR_h0...
2. Core Java Important Interview QA : https://www.youtube.com/watch?v=CFoxr...
3. Spring MVC & Spring Boot :: https://www.youtube.com/watch?v=f-Wk1...
4. Micro Services :: https://www.youtube.com/watch?v=pscya...
5. Git/GitHub :: https://www.youtube.com/watch?v=XHxBA...
6. AWS :: https://www.youtube.com/watch?v=81Y_2...
7. Spring Security & OAuth : https://www.youtube.com/watch?v=AvV8l...
8. Coding and Programming : https://www.youtube.com/watch?v=o2BP4...
9. Raspberry PI & Arduino : https://www.youtube.com/watch?v=uauMF...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Watch my "Most Watched Videos"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
► HTTPS & HTTPS protocol :: https://www.youtube.com/watch?v=BlnSS...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Information
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Spring Core Interview Question and Ans
1. How types of container present in Spring ?
Ans : Spring provides two types of containers.
1. BeanFactory container
2. ApplicationContext container
Bean Factory
• Bean instantiation/wiring
Application Context
• Bean instantiation/wiring
• Automatic BeanPostProcessor registration
• Automatic BeanFactoryPostProcessor registration
• Convenient MessageSource access (for i18n)
• ApplicationEvent publication

BeanFactory interface provides basic features only thus requires less memory. For standalone applications where the basic features are enough and when memory consumption is critical, we can use BeanFactory. ApplicationContext provides all the basic features and advanced features, including several that are geared towards enterprise applications thus requires more memory.

A BeanFactory is essentially nothing more than the interface for an advanced factory capable of maintaining a registry of different beans and their dependencies.
The BeanFactory enables us to read bean definitions and access them using the bean factory.
InputStream is = new FileInputStream("beans.xml");
BeanFactory factory = new XmlBeanFactory(is);

//Get bean
HelloWorld obj = (HelloWorld) factory.getBean("helloWorld");

Alternative:
Resource resource = new FileSystemResource("beans.xml");
BeanFactory factory = new XmlBeanFactory(resource);

ClassPathResource resource = new ClassPathResource("beans.xml");
BeanFactory factory = new XmlBeanFactory(resource);

ApplicationContext
ApplicationContext container adds more enterprise-specific functionality such as the ability to resolve textual messages from a properties file and the ability to publish application events to interested event listeners. This container is defined by the org.springframework.context.ApplicationContext interface.
The ApplicationContext container includes all functionality of the BeanFactory container, so it is generally recommended over the BeanFactory. BeanFactory can still be used for lightweight applications like mobile devices or applet based applications where data volume and speed is significant.
Types of ApplicationContext
The most commonly used ApplicationContext implementations are:
1. FileSystemXmlApplicationContext – This container loads the definitions of the beans from an XML file. Here you need to provide the full path of the XML bean configuration file to the constructor.
2. ClassPathXmlApplicationContext – This container loads the definitions of the beans from an XML file. Here you do not need to provide the full path of the XML file but you need to set CLASSPATH properly because this container will look bean configuration XML file in CLASSPATH.
3. WebXmlApplicationContext – This container loads the XML file with definitions of all beans from within a web application.
4. ApplicationContext context = new FileSystemXmlApplicationContext("beans.xml");
5. HelloWorld obj = (HelloWorld) context.getBean("helloWorld");

Thanks & Regards,
Debu Paul

Комментарии

Информация по комментариям в разработке