go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Way#1 Retrieve bean from the IoC Container by application
 
Subject: Way#1 Retrieve bean from the IoC Container by application
Author: WebSpider
In response to: 2 Ways to Use Spring Bean
Posted on: 10/21/2019 05:40:51 AM

First, the IoC Container context should be generated via the corresponding configuration:

  • For XML configuration based bean -- context = new ClassPathXmlApplicationContext("app-config.xml");
  • For Java configuration based bean -- context = new AnnotationConfigApplicationContext(BeanConfig.class);
  • For annotation based bean -- context = new FileSystemXmlApplicationContext("/path/app-config.xml");


    Secondly, retrieve bean from the IoC Container via the context
    	Name_XML_Bean bean = context.getBean(Name_XML_Bean.class); 	
    



     

    > On 10/21/2019 05:34:31 AM WebSpider wrote:


    The life cycle (from instantiation to garbage collection) of Spring beans are controller by Spring IoC Container, but those beans are always standby and ready for use. There are two way to use Spring beans:

  • External Use -- Retrieve from the IoC Container by application
  • Internal Use -- Fulfill the dependency need for another bean from the IoC container.





    References:

  •  


     
    Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
     
    Get your own forum today. It's easy and free.