How to start Spring containers like we start Tomcat container by simply start and stop ?




We have interfaces in containers and corresponding classes to start to start these containers.as in screen below...

IOC Hierarchy (Factory, Classes and Interfaces)

DriverManager.getConnection() will give a Connection object, in same way WebApplicationContextUtil is a factory class which will give WebApplicationConext object.

HelloWorld (required below) 

1. Pojo
2. XML
3. Client class (Driver class) 

------------------------------------------------------------------


HelloWord Sample :



Test.java (Pojo class)
 ---------------------------------------------------------------------------------
/**
 * Hello world!
 *
 */
public class App
{
    public static void main( String[] args )
    {
        System.out.println(" Hello World !!!");
    }
}



Spring XML :

spring.xml
----------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc.xsd
     http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
     http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context-4.0.xsd>
   
   
    <beans:bean id="test" class="com.demo.Test">
   
</beans>




Client.java (run this class)
---------------------------------------------------------

 public class Client
{
    public static void main( String[] args )
    {
        Resource r = new ClassathResource("spring.xml");
        BeanFactory factory = new XMLBeanFactory(r);
        factory.getBean("test");
    }
}



Output:
---------------------------------------------------------

 Hello World !!!



Next:What is the Basic difference between BeanFactory and ApplicationContext ?



No comments:

Post a Comment

Fixing yum command on linux

You may find yourself having to fix more packages. So you can just remove everything you had installed via  pip and reinstall everythin...