此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Modulith 1.3.0! |
Moments — 时间流逝事件 API
spring-modulith-moments
是一个 Passage of Time Events 实现,深受 Matthias Verraes 博客文章的启发。
这是一种基于事件的时间方法,用于触发与经过的特定时间段相关的作。
要使用抽象,请在项目中包括以下依赖项:
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-moments</artifactId>
</dependency>
dependencies {
implementation 'org.springframework.modulith:spring-modulith-moments'
}
添加到项目 Classpath 的依赖项会导致应用程序中出现以下情况:
-
应用程序代码可以引用
HourHasPassed
,DayHasPassed
,WeekHasPassed
,MonthHasPassed
,QuarterHasPassed
,YearHasPassed
键入 Spring 事件侦听器,以便在经过一定时间时收到通知。 -
类型
org.springframework.modulith.Moments
在ApplicationContext
,其中包含触发这些事件的逻辑。 -
如果
spring.modulith.moments.enable-time-machine
设置为true
,则该实例将为org.springframework.modulith.TimeMachine
它允许 “shift” 时间并触发所有中间事件,这对于由事件触发的集成测试功能很有用。
默认情况下,Moments 使用Clock.systemUTC()
实例。要自定义此 Bean,请声明一个Clock
.
-
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 公开了以下应用程序属性以进行高级自定义:
财产 | 默认值 | 描述 |
---|---|---|
|
假 |
如果设置为 |
|
小时 |
要触发的事件的最小粒度。替代值 |
|
|
这 |
|
|
季度开始的月份。 |
|
|
这 |