org.springframework.context.ApplicationContext.publishEvent()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(201)

本文整理了Java中org.springframework.context.ApplicationContext.publishEvent()方法的一些代码示例,展示了ApplicationContext.publishEvent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ApplicationContext.publishEvent()方法的具体详情如下:
包路径:org.springframework.context.ApplicationContext
类名称:ApplicationContext
方法名:publishEvent

ApplicationContext.publishEvent介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

private void publishEvent(@Nullable Object event) {
  if (event != null) {
    Assert.notNull(this.applicationContext, "ApplicationContext must not be null");
    this.applicationContext.publishEvent(event);
  }
}

代码示例来源:origin: org.springframework/spring-context

private void publishEvent(@Nullable Object event) {
  if (event != null) {
    Assert.notNull(this.applicationContext, "ApplicationContext must not be null");
    this.applicationContext.publishEvent(event);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
  if (bean instanceof ExampleBean) {
    this.applicationContext.publishEvent(new ExampleApplicationEvent(this));
  }
  return bean;
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
  this.applicationContext.publishEvent(new MyEvent(this));
  return bean;
}

代码示例来源:origin: prontera/spring-cloud-rest-tcc

/**
 * 本资源回收策略为定时轮询数据库, 存在资源竞争与重复计算的嫌疑, 待后续版本优化
 */
@Scheduled(fixedRate = 1000)
public void autoCancelTrying() {
  // 获取过期的资源
  final Set<ProductStockTcc> reservations = tccMapper.selectExpireReservation(100);
  for (ProductStockTcc res : reservations) {
    context.publishEvent(new ProductStockCancellationEvent(res));
  }
}

代码示例来源:origin: prontera/spring-cloud-rest-tcc

/**
 * 本资源回收策略为定时轮询数据库, 存在资源竞争与重复计算的嫌疑, 待后续版本优化
 */
@Scheduled(fixedRate = 1000)
public void autoCancelTrying() {
  // 获取过期的资源
  final Set<UserBalanceTcc> reservations = balanceTccMapper.selectExpireReservation(100);
  for (UserBalanceTcc res : reservations) {
    context.publishEvent(new ReservedBalanceCancellationEvent(res));
  }
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
  public void afterCompletion(int status) {
    if (status == TransactionSynchronization.STATUS_COMMITTED) {
      ApplicationContextHolder.getApplicationContext().publishEvent(new OrderPersistedEvent((Order) entity));
    }
  }
});

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
  public void afterCommit() {
    ApplicationContextHolder.getApplicationContext().publishEvent(new CustomerPersistedEvent((Customer) entity));
  }
});

代码示例来源:origin: spring-projects/spring-framework

this.parent.publishEvent(event);

代码示例来源:origin: AxonFramework/AxonFramework

@Override
  public void afterPropertiesSet() {
    messageSource.subscribe(msgs -> msgs.forEach(msg -> {
      ApplicationEvent converted = convert(msg);
      if (converted != null) {
        applicationContext.publishEvent(convert(msg));
      }
    }));
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void applicationEventListener() {
  ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
  Messenger eventListener = (Messenger) ctx.getBean("eventListener");
  ctx.publishEvent(new MyEvent(ctx));
  assertEquals("count=2", eventListener.getMessage());
}

代码示例来源:origin: geoserver/geoserver

@Override
  public void contextInitialized(ServletContextEvent event) {
    super.contextInitialized(event);
    ApplicationContext appContext = getCurrentWebApplicationContext();
    if (appContext != null) {
      appContext.publishEvent(new ContextLoadedEvent(appContext));
    }
  }
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
  public void afterCommit() {
    ApplicationContextHolder.getApplicationContext().publishEvent(new CustomerPersistedEvent(((CustomerPayment) entity).getCustomer()));
  }
});

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
  public void afterCommit() {
    ApplicationContextHolder.getApplicationContext().publishEvent(new CustomerPersistedEvent(((CustomerAddress) entity).getCustomer()));
  }
});

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
  public void afterCommit() {
    ApplicationContextHolder.getApplicationContext().publishEvent(new CustomerPersistedEvent(((CustomerPhone) entity).getCustomer()));
  }
});

代码示例来源:origin: org.springframework.boot/spring-boot

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
  ApplicationContext context = event.getApplicationContext();
  if (context instanceof ConfigurableApplicationContext
      && context == event.getSource()) {
    context.publishEvent(new ParentContextAvailableEvent(
        (ConfigurableApplicationContext) context));
  }
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void targetDoesntLoseApplicationListenerInterface() {
  assertThat(appContext.getBeansOfType(ApplicationListener.class)).hasSize(1);
  assertThat(appContext.getBeanNamesForType(ApplicationListener.class)).hasSize(1);
  appContext.publishEvent(new AuthenticationSuccessEvent(
      new TestingAuthenticationToken("user", "")));
  assertThat(target).isInstanceOf(ApplicationListener.class);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testEventPublicationInterceptor() throws Throwable {
  MethodInvocation invocation = mock(MethodInvocation.class);
  ApplicationContext ctx = mock(ApplicationContext.class);
  EventPublicationInterceptor interceptor = new EventPublicationInterceptor();
  interceptor.setApplicationEventClass(MyEvent.class);
  interceptor.setApplicationEventPublisher(ctx);
  interceptor.afterPropertiesSet();
  given(invocation.proceed()).willReturn(new Object());
  given(invocation.getThis()).willReturn(new Object());
  interceptor.invoke(invocation);
  verify(ctx).publishEvent(isA(MyEvent.class));
}

代码示例来源:origin: cloudfoundry/uaa

public void destroy() {
  UaaPrincipal justEnoughPrincipal = new UaaPrincipal(
      "id", "name", "", identityProvider.getOriginKey(), "external id", identityZone.getId()
  );
  UaaAuthentication justEnoughAuthentication = new UaaAuthentication(
      justEnoughPrincipal, Lists.newArrayList(), null
  );
  applicationContext.publishEvent(new EntityDeletedEvent<>(identityZone, justEnoughAuthentication));
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
public ProcessContext<CheckoutSeed> execute(ProcessContext<CheckoutSeed> context) throws Exception {
  CheckoutSeed seed = context.getSeedData();
  seed.getOrder().setStatus(getCompletedStatus());
  seed.getOrder().setOrderNumber(determineOrderNumber(seed.getOrder()));
  seed.getOrder().setSubmitDate(determineSubmitDate(seed.getOrder()));
  OrderSubmittedEvent event = new OrderSubmittedEvent(seed.getOrder().getId(), seed.getOrder().getOrderNumber());
  applicationContext.publishEvent(event);
  return context;
}

相关文章