zoukankan      html  css  js  c++  java
  • Spring DM所提供的Bundle监听接口OsgiBundleApplicationContextListener

    通过使用Spring DM提供的监听接口,我们可以更好的对服务进行管控,其实该接口也非常简单就能使用上,只要自定义一个类实现OsgiBundleApplicationContextListener接口,实现onOsgiApplicationEvent方法,并将自定义类注册成OSGI服务,通过判断event的事件类型来执行相应逻辑处理,同时也可以获取到当前监听的Bundle,从而达到更深层次的监控,

    public class ListenerDemo implements OsgiBundleApplicationContextListener{
    
        @Override
        public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent event) {
            
            String bundleName = event.getBundle().getSymbolicName();
            
            if (event instanceof OsgiBundleContextRefreshedEvent) {//Spring上下文创建成功事件
                System.out.println("服务启动");
            }else if (event instanceof OsgiBundleContextClosedEvent) {//Spring上下文销毁事件
                System.out.println("服务关闭");
                
            }
        }
    }
    <bean id="ListenerDemo" class="com.sample.service.listener.ListenerDemo"></bean>
        
        <osgi:service ref="ListenerDemo" interface="org.springframework.osgi.context.event.OsgiBundleApplicationContextListener"/>
  • 相关阅读:
    【Jenkins】坑
    【Windows】修改hosts
    【Linux】防火墙操作-centos7
    【Linux】学习-centos 7
    【Jenkins】介绍、安装
    【Jenkins】有关网站
    【Jenkins】中文汉化
    【Jenkins】修改Jenkins插件为国内源
    python笔记之孤单的元组
    python笔记之水仙花数
  • 原文地址:https://www.cnblogs.com/xufan/p/6407492.html
Copyright © 2011-2022 走看看