Tutorials

Spring IOC Container


Application Context


Application Context is another spring container other than Bean Factories.

 

Java POJO

public class SampleExample {

   public void printTest(){
     System.out.println("Testing Bean factory");
   }
}

 

Xml configuration

<beans  
    xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:p="http://www.springframework.org/schema/p"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans  
               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">  
 
<bean id="SampleExampleBean" class="SampleExample"></bean
</beans>

 

 

Test Class

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

   public class TestSpringClass {

      public static void main(String[] args) {

      ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

      SampleExample example = (SampleExample) context.getBean("SampleExampleBean");
      example.printTest();
  }
}

OUTPUT:
Testing Bean factory
 


Please Share this page
Views : 51
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!