Moments — 一个时间流逝事件 API
Spring Shell这是一个深受Matthias Verraes博客文章启发的《时间流逝事件》实现。
这是一种基于事件的时间处理方法,用来触发与特定时间段相关联的动作。
要使用抽象,可以在你的项目中包含以下依赖关系:
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-moments</artifactId>
</dependency>
dependencies {
implementation 'org.springframework.modulith:spring-modulith-moments'
}
项目类路径中添加的依赖会导致你的应用程序出现以下情况:
-
应用代码可以指
时间已过,日子已逝,周已过去,月已过去,季度已过,岁月已逝通过输入春季活动听众,以便在时间过了一定时间时收到通知。 -
一个典型的豆子
org.springframework.modulith.Moments可在应用上下文其中包含触发这些事件的逻辑。 -
如果
Spring.Modulith.moments.enable-time-machine设置为true,该实例将是org.springframework.modulith.TimeMachine这允许“移动”时间,从而触发所有中间事件,这对由事件触发的集成测试功能非常有用。
默认情况下,Moments 使用一个Clock.systemUTC()实例。为了定制,可以声明一个类型的豆子时钟.
-
Java
-
Kotlin
@Configuration
class MyConfiguration {
@Bean
Clock myCustomClock() {
// Create a custom Clock here
}
}
@Configuration
class MyConfiguration {
@Bean
fun myCustomClock(): Clock {
// Create a custom Clock here
}
}
Moments 展示了以下应用属性,供高级定制:
| 属性 | 默认值 | 描述 |
|---|---|---|
|
false |
如果设置为 |
|
小时 |
触发事件的最小细度。备选价值 |
|
|
这 |
|
|
学期开始的月份。 |
|
|
这 |