The connection and difference between ApplicationContext and BeanFactory

  1. The APPlicationContext interface inherits the HierachicalBeanFactory interface, which in turn inherits the BeanFactory interface. Therefore, ApplicationContext is much broader and more powerful than BeanFactory.
public interface ApplicationContext extends EnvironmentCapable, ListableBeanFactory,HierarchicalBeanFactory,MessageSource, ApplicationEventPublisher, ResourcePatternResolver { ...... } public interface HierarchicalBeanFactory extends BeanFactory { ...... }Copy the code

2.ApplicationContext has more important functions than BeanFactory, such as obtaining computer environment, obtaining resources, publishing events, internationalization, etc.

Public Interface ApplicationContext extends EnvironmentCapable, ResourcePatternResolver, ApplicationEventPublisher, MessageSource{ ...... }Copy the code

The difference between ClassPathxmlApplicationContext and AnntationConfigApplicationContext.

  1. Read the file, ClassPathxmlApplicationContext read XML configuration files, and read AnntationConfigApplicationContext Class files in the configuration Class. If use AnnotationConfigApplicationContext reads the XML file, not to be read.

2. The function of the support is not the same, both are inherited AbstractApplicationContext interface. But the intermediate links ClassPathxmlApplicationContext inherited AbstractRefreshAbleApplicationContext, Much more so ClassPathxmlApplicationContext relative to AnntationConfigApplicationContext a Refresh (Refresh) the function of the interface. This function is similar to restarting the container.

public class ClassPathXmlApplicationContext extends AbstractXmlApplicationContext { .... } public abstract class AbstractXmlApplicationContext extends AbstractRefreshableConfigApplicationContext { .... } public abstract class AbstractRefreshableConfigApplicationContext extends AbstractRefreshableApplicationContext implements BeanNameAware, InitializingBean {..... }Copy the code
public class AnnotationConfigApplicationContext extends GenericApplicationContext implements AnnotationConfigRegistry {... } public class GenericApplicationContext extends AbstractApplicationContext implements BeanDefinitionRegistry {....... }Copy the code