Home Tutorial Spring Spring3 Ioc ApplicationContextAware in spring


Share on Google+Share on Google+
ApplicationContextAware in spring
Posted on: September 3, 2010 at 12:00 AM
In this tutorial you will learn about ApplicationContextAware Interface of Spring Framework.

ApplicationContextAware in spring

In this tutorial you will see and example of using ApplicationContextAware. The ApplicationContextAware is used when an object required.


package com.roseindia.common;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class StudentBean implements ApplicationContextAware {
	private ApplicationContext context;

	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		context = applicationContext;


package com.roseindia.common;

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

public class AppMain {

	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext(
		StudentBean bean = (StudentBean) context.getBean("studentBean");


<beans xmlns="http://www.springframework.org/schema/beans"
  <bean id="studentBean" class="com.roseindia.common.StudentBean" />

When you run this application it will display message as shown below:

org.springframework.context.support.ClassPathXmlApplicationContext@18a47e0: startup date [Fri Sep 03 16:15:55 GMT+05:30 2010]; root of
context hierarchy

Download this example code


Related Tags for ApplicationContextAware in spring :

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 3, 2010

Recommend the tutorial

Advertisements Advertisements