Moments — 一个时间流逝事件 API

Spring Shell这是一个深受Matthias Verraes博客文章启发的《时间流逝事件》实现。 这是一种基于事件的时间处理方法,用来触发与特定时间段相关联的动作。spring-doc.cadn.net.cn

要使用抽象,可以在你的项目中包含以下依赖关系:spring-doc.cadn.net.cn

<dependency>
  <groupId>org.springframework.modulith</groupId>
  <artifactId>spring-modulith-moments</artifactId>
</dependency>
dependencies {
  implementation 'org.springframework.modulith:spring-modulith-moments'
}

项目类路径中添加的依赖会导致你的应用程序出现以下情况:spring-doc.cadn.net.cn

  • 应用代码可以指时间已过,日子已逝,周已过去,月已过去,季度已过,岁月已逝通过输入春季活动听众,以便在时间过了一定时间时收到通知。spring-doc.cadn.net.cn

  • 一个典型的豆子org.springframework.modulith.Moments可在应用上下文其中包含触发这些事件的逻辑。spring-doc.cadn.net.cn

  • 如果Spring.Modulith.moments.enable-time-machine设置为true,该实例将是org.springframework.modulith.TimeMachine这允许“移动”时间,从而触发所有中间事件,这对由事件触发的集成测试功能非常有用。spring-doc.cadn.net.cn

默认情况下,Moments 使用一个Clock.systemUTC()实例。为了定制,可以声明一个类型的豆子时钟.spring-doc.cadn.net.cn

@Configuration
class MyConfiguration {

  @Bean
  Clock myCustomClock() {
    // Create a custom Clock here
  }
}
@Configuration
class MyConfiguration {

  @Bean
  fun myCustomClock(): Clock {
    // Create a custom Clock here
  }
}

Moments 展示了以下应用属性,供高级定制:spring-doc.cadn.net.cn

表1。可用的应用属性
属性 默认值 描述

Spring.Modulith.moments.enable-time-machinespring-doc.cadn.net.cn

falsespring-doc.cadn.net.cn

如果设置为true时刻实例将是一个时间机器,这会让API将时间向前移动。对于期望由时间流逝事件触发的功能集成测试非常有用。spring-doc.cadn.net.cn

Spring.Modulith.Moments.granularityspring-doc.cadn.net.cn

小时spring-doc.cadn.net.cn

触发事件的最小细度。备选价值以避免每小时的事件。spring-doc.cadn.net.cn

spring.modulith.moments.localespring-doc.cadn.net.cn

Locale.getDefault()spring-doc.cadn.net.cn

现场用于确定周数边界。spring-doc.cadn.net.cn

春季。模态。时刻。季度-开始-月spring-doc.cadn.net.cn

月份。一月spring-doc.cadn.net.cn

学期开始的月份。spring-doc.cadn.net.cn

Spring.modulith.moments.zone-idspring-doc.cadn.net.cn

区域偏移#UTCspring-doc.cadn.net.cn

ZoneID确定与已发布事件相关的时间。spring-doc.cadn.net.cn