Share on Google+Share on Google+

ApplicationContextAware in spring

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.ApplicationContext;

public class AppMain {

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


<beans xmlns=""
  <bean id="studentBean" class="com.roseindia.common.StudentBean" />

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

org[email protected]18a47e0: startup date [Fri Sep 03 16:15:55 GMT+05:30 2010]; root of
context hierarchy

Download this example code



Posted on: September 3, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.


Advertisement null