ApplicationContext or AbstractApplicationContext in Spring Framework

ApplicationContext or AbstractApplicationContext in Spring Framework

With using the ApplicationContext interface.

package com.linaittech1;

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

public class MainApp {

    public static void main(String[] args) {
       
        ApplicationContext context = new FileSystemXmlApplicationContext (“file:/home/poganin/worksSpringer/Spring2/src/Beans.xml”);
        Mirek obj = (Mirek) context.getBean(“mirek”);
        obj.getMessage();
       
        ApplicationContext context1 = new FileSystemXmlApplicationContext (“file:/home/poganin/worksSpringer/Spring2/src/Beans.xml”);
        Lak obj1 = (Lak) context1.getBean(“lak”);
        obj1.getNum1();
        obj1.getNum2();
        obj1.getSum();
       
    }

}

With using the AbstractApplicationContext interface.

package com.linaittech1;

import org.springframework.context.AbstractApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class MainApp {

    public static void main(String[] args) {
        
        AbstractApplicationContext context = new FileSystemXmlApplicationContext (“file:/home/poganin/worksSpringer/Spring2/src/Beans.xml”);
        Mirek obj = (Mirek) context.getBean(“mirek”);
        obj.getMessage();
        context.registerShutdownHook();
        
        AbstractApplicationContext context1 = new FileSystemXmlApplicationContext (“file:/home/poganin/worksSpringer/Spring2/src/Beans.xml”);
        Lak obj1 = (Lak) context1.getBean(“lak”);
        obj1.getNum1();
        obj1.getNum2();
        obj1.getSum();
        context1.registerShutdownHook();
        
    }

}

You probably see the difference. With AbstractApplicationContext, we have a great possibility to shutdown our bean. Sometimes, it’s simply good to use the second method.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s