第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

范圍內(nèi)的 Spring 事件可能嗎?

范圍內(nèi)的 Spring 事件可能嗎?

Go
開滿天機(jī) 2021-05-31 09:11:01
Spring 事件機(jī)制支持發(fā)布應(yīng)用程序事件并通過@EventListener注解在 Spring 組件內(nèi)監(jiān)聽這些事件。但是,我在文檔中找不到有關(guān)在特定范圍內(nèi)發(fā)送事件的任何信息。我對 Vaadin 的具體需求是:在用戶交互的上下文中,發(fā)送事件(例如登錄事件)此事件應(yīng)僅由相同的 bean 使用@UIScope,即不應(yīng)影響其他用戶 UI那可能嗎?注意:這并不是 Vaadin 特有的。我還可以詢問如何使用 Spring web mvc 請求范圍來完成。
查看完整描述

2 回答

?
慕少森

TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個(gè)贊

請看看這是否是您要找的:


主要應(yīng)用:


   package com.fg7.evision.EventList;


    import org.springframework.context.annotation.AnnotationConfigApplicationContext;

    import org.springframework.context.annotation.ComponentScan;


    @ComponentScan(basePackages = "com.fg7.evision.EventList")

    public class EventApplication {



        public static void main(String[] args) {

           MyScopedEvent event = new MyScopedEvent("hello world");

           AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(EventApplication.class);

            ctx.publishEvent(event);

        }


    }

事件 :


 package com.fg7.evision.EventList;


    public class MyScopedEvent  {


        private String message;


        public MyScopedEvent( String message) {

            this.message = message;

        }


        public String getMessage() {

            return message;

        }

    }

事件偵聽器的范圍僅限于單例范圍。


package com.fg7.evision.EventList;


import org.springframework.beans.factory.BeanNameAware;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.ConfigurableApplicationContext;

import org.springframework.context.event.EventListener;

import org.springframework.stereotype.Component;


@Component(value = "listener")

public class ScopedEventListener implements BeanNameAware {


    @Autowired

    ConfigurableApplicationContext context;


    String beanName;


    @Override

    public void setBeanName(String name) {

        this.beanName = name;

    }


    @EventListener(condition = "@listener.getScope() == 'singleton'")

    public void handleEvent(MyScopedEvent myScopedEvent) {

        System.out.println(myScopedEvent.getMessage());


    }


    public String getScope(){

        return this.context.getBeanFactory().getBeanDefinition(this.beanName).getScope();

    }



}


查看完整回答
反對 回復(fù) 2021-06-02
  • 2 回答
  • 0 關(guān)注
  • 229 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號