Skip to content

Spring Framework Blog

Menu
  • Home
  • Spring
  • Spring Boot
  • About
Menu

Spring Aware Interfaces

Posted on June 10, 2024June 11, 2024 by wpadmin

Table of Contents

Toggle
  • ApplicationContextAware
  • BeanNameAware
  • DestructionAwareBeanPostProcessor

ApplicationContextAware

Provides a reference to ApplicationContext in to the bean;

@Component
public class BeanPostProcessorExtension implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}

BeanNameAware

Provides a reference to the name of the bean derived from it’s bean definition.

public class BeanContextAware extends BaseBean implements BeanNameAware{
    public String name;
    @Override
    public void setBeanName(String name) {
        this.name = name;

    }
}

DestructionAwareBeanPostProcessor

Subinterface of BeanPostProcessor that adds a before-destruction callback.

public class DestructionAwareBeanPostProcessorExtension implements DestructionAwareBeanPostProcessor {

    @Override
    public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException {

    }

    @Override
    public boolean requiresDestruction(Object bean) {
        return DestructionAwareBeanPostProcessor.super.requiresDestruction(bean);
    }
}

References

  • Spring
  • Documentation
  • References
  • Toc
  • Books
  • Certification
  • AOP
  • Config
  • Java
  • Java core
  • JDBC
  • JPA
  • Rest
  • Security
  • Spring
  • Spring Boot
  • Spring Core
  • Spring Data
  • Spring MVC
  • Spring Rest
  • Spring Security
  • Tests
  • Transactions
  • Uncategorized

Recent Posts

  • Spring Annotations
  • Java Tests
  • Java operators
  • Java versions
  • Java Oracle Licenses
  • Configuration properties
  • MockMvc
  • Spring Security III
  • MVC Controller Method Params
  • JPA Methods
  • Transaction propagation and isolation
  • Spring JDBC
  • Spring Boot Auto-Configuration
  • Spring Resource interface
  • JSR 330 Standard Annotations
  • Spring Aware Interfaces
  • Spring Transactions
  • Spring Boot Core
  • MVC Rest
  • Spring Boot JPA
©2025 Spring Framework Blog | Built using WordPress and Responsive Blogily theme by Superb