spring一些特的梳理

阅读更多 spring bean的生命周期回调 初始化回调:为同一个bean配置的多个生命周期机制具有不同的初始化方法,如下所示: 用注释方法注释 @PostConstruct afterProp...
阅读更多

spring bean的生命周期回调

初始化回调:为同一个bean配置的多个生命周期机制具有不同的初始化方法,如下所示:

用注释方法注释 @PostConstruct

afterPropertiesSet()由InitializingBean回调接口定义

自定义配置的init()方法

毁灭回调:Destroy方法以相同的顺序调用:

用注释方法注释 @PreDestroy

destroy()由DisposableBean回调接口定义

自定义配置的destroy()方法

启动回调:

关闭回调:

参看:

https://blog.csdn.net/soonfly/article/details/69916806

优雅关闭spring  ioc容器用官方提供的钩子即可

import org.springframework.context.ConfigurableApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public final class Boot {

    public static void main(final String[] args) throws Exception {

        ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");

        // add a shutdown hook for the above context...

        ctx.registerShutdownHook();

        // app runs here...

        // main method exits, hook is called prior to the app shutting down...

    }

spring的一系列感知接口ApplicationContextAware 。。。这个可以获取spring上下文,进而获取bean

使用JSR 330标准注释

<dependency>

    <groupId>javax.inject</groupId>

    <artifactId>javax.inject</artifactId>

    <version>1</version>

</dependency>

jsr 330 注释 和spring常规的注解作用相仿@Autowired----@Inject   @Component--- @Named / @ManagedBean

分享到:
评论

原文出处:https://yuhuiblog69568268256398425858309.iteye.com/blog/2436359

  • 发表于 2019-01-10 19:37
  • 阅读 ( 312 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除