this.refreshContext(context);

this.refreshContext(context);

当前context类型:
在这里插入图片描述

SpringApplication.refreshContext

在这里插入图片描述
在这里插入图片描述
可以看到,容器的刷新操作还是由容器自己实现。

  1. AnnotationConfigServletWebServerApplicationContext 没有自己的refresh操作,使用了父类的refresh(ServletWebServerApplicationContext)

ServletWebServerApplicationContext#refresh

public final void refresh() throws BeansException, IllegalStateException {
        try {
            super.refresh();
        } catch (RuntimeException var3) {
            WebServer webServer = this.webServer;
            if (webServer != null) {
                webServer.stop();
            }

            throw var3;
        }
    }

父类ServletWebServerApplicationContext在使用它的父类refresh的继承上的增加了一些东西。它的父类本来是GenericWebApplicationContext,但是它的父类使用的是顶层抽象类AbstractApplicationContext的refresh方法。

所以AnnotationConfigServletWebServerApplicationContext 用的是AbstractApplicationContext的refresh方法来刷新自己。

AbstractApplicationContext#refresh —— Spring启动过程中最重要的场景
  public void refresh() throws BeansException, IllegalStateException {
        synchronized(this.startupShutdownMonitor) {
            StartupStep contextRefresh = this.applicationStartup.start("spring.context.refresh");
            this.prepareRefresh();
            ConfigurableListableBeanFactory beanFactory = this.obtainFreshBeanFactory();
            this.prepareBeanFactory(beanFactory);

            try {
                this.postProcessBeanFactory(beanFactory);
                StartupStep beanPostProcess = this.applicationStartup.start("spring.context.beans.post-process");
                this.invokeBeanFactoryPostProcessors(beanFactory);
                this.registerBeanPostProcessors(beanFactory);
                beanPostProcess.end();
                this.initMessageSource();
                this.initApplicationEventMulticaster();
                this.onRefresh();
                this.registerListeners();
                this.finishBeanFactoryInitialization(beanFactory);
                this.finishRefresh();
            } catch (BeansException var10) {
                if (this.logger.isWarnEnabled()) {
                    this.logger.warn("Exception encountered during context initialization - cancelling refresh attempt: " + var10);
                }

                this.destroyBeans();
                this.cancelRefresh(var10);
                throw var10;
            } finally {
                this.resetCommonCaches();
                contextRefresh.end();
            }

        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
function webAudio(options){ //public this.volume = parseInt(options.volume || 100) ; // 音量控制单元,值为Number类型,范围为0-100 this.url = options.url || '' ; // 音频资源url,值类型为String类型 this.autoPlay = !!options.autoPlay; // 是否加载完成自动播放,值类型为Boolean类型 this.loopPlay = !!options.loopPlay; // 是否循环播放,值类型为Boolean类型 //private this.buffer = null; this.context = null; this.sourceAudio = null; this.gainNode = null; this.loadReady = false; //初始化 this.init = function () { window.AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.msAudioContext; if(!AudioContext){ console.error("您的浏览器不支持HTML5 audio API"); return } this.context = new AudioContext(); this.loadResource(); } //下载音频资源 this.loadResource = function () { var _this = this; var xhr = new XMLHttpRequest(); xhr.open('GET',this.url,true); xhr.responseType = 'arraybuffer'; xhr.onload = function () { _this.context.decodeAudioData(xhr.response,function (buffer) { _this.buffer = buffer; _this.prepareAudio(); this.loadReady = true; }) } xhr.send(); } //是否自动播放 this.prepareAudio = function () { this.autoPlay ? this.startAudio() : ''; } //创建音频 this.createAudio = function () { this.sourceAudio = this.context.createBufferSource();//创建一个音频源 相当于是装音频的容器 this.sourceAudio.buffer = this.buffer;// 告诉音频源 播放哪一段音频 this.gainNode = this.context.createGain();//调节音量 this.sourceAudio.connect(this.gainNode); this.changeVolume();//声音 this.sourceAudio.loop = this.loopPlay;//循环 this.gainNode.connect(this.context.destination);// 连接到输出源 } //重新播放 this.startAudio = function () { this.createAudio(); this.sourceAudio.start(0);//开始播放 } //改变音量 this.changeVolume = function (num) { num = num || 0; this.gainNode.gain.value = (this.volume += num) / 100; } //播放转为暂停 this.pauseAudio = function () { this.gainNode.disconnect(this.context.destination) } //暂停转为播放 this.playAudio = function () { this.gainNode.connect(this.context.destination) } //停止播放 this.stopAudio = function () { this.sourceAudio.stop() } //减小声音 this.decVolume = function () { if(this.volume >= 10){ this.changeVolume(-10); } } //增大声音 this.ascVolume = function () { if(this.volume <= 90){ this.changeVolume(10); } } //静音 this.quietVolume = function () { this.gainNode.gain.value = 0; } //静音恢复 this.recoverVolume = function () { this.changeVolume() } //当前音量 this.getVolume = function () { return (this.gainNode.gain.value).toFixed(2) * 100; } this.init(); return this; } window.test = new webAudio({ volume:100, url:'1.mp3', autoPlay:true, loopPlay:true }); //控制台事件 var pauseEle = document.getElementById("pause"); pauseEle.onclick = function() { if (pauseEle.alt === 'Pause') { test.pauseAudio(); } else { test.playAudio(); } }增加播放暂停图片切换
06-12

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值