79768227

Date: 2025-09-18 09:24:23
Score: 0.5
Natty:
Report link

Yes, the @Timestamp annotation is mandatory for @EventSourcingHandler methods in Axon Framework. While @EventHandler methods can automatically resolve Instant parameters to the event timestamp, @EventSourcingHandler methods require explicit annotation. Your current implementation with @Timestamp Instant requestedAt is correct and should be maintained.

//CORRECT USE - @Timestamp must be added
@EventSourcingHandler
public void on(FooEvent event, @Timestamp Instant requestedAt) {
  // requestAt now contains the event's timestamp
}

Difference between @EventHandler and @EventSourcingHandler:

In @EventHandler methods, Axon automatically populates Instant parameters with the event timestamp.

In @EventSourcingHandler methods, the explicit @Timestamp annotation is required.

// CORRECT USAGE - @Timestamp must be added.

@EventSourcingHandler

public void on(FooEvent event, @Timestamp Instant requestedAt) {

// requestedAt now contains the event's timestamp.

}

Solution for test error:

Adding @Timestamp will now recognize the parameter, and the "No resource of type Instant" error will disappear.

Alternative solution (carrying timestamp within the event):

// Your Event class

public class FooEvent {

private Instant timestamp;

// getter/setter

}

// In EventSourcingHandler

@EventSourcingHandler

public void on(FooEvent event) {

Instant requestedAt = event.getTimestamp(); // Use the event's own timestamp

}

This may be a documentation oversight/ambiguity, but technically the correct behavior is to require @Timestamp annotation for @EventSourcingHandler. You should continue using your existing working code (with @Timestamp).

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Timestamp
  • User mentioned (0): @EventSourcingHandler
  • User mentioned (0): @EventHandler
  • User mentioned (0): @EventSourcingHandler
  • User mentioned (0): @Timestamp
  • User mentioned (0): @EventHandler
  • User mentioned (0): @EventSourcingHandler
  • User mentioned (0): @EventHandler
  • User mentioned (0): @EventSourcingHandler
  • User mentioned (0): @Timestamp
  • User mentioned (0): @Timestamp
  • User mentioned (0): @EventSourcingHandler
  • User mentioned (0): @Timestamp
  • User mentioned (0): @Timestamp
  • User mentioned (0): @EventSourcingHandler
  • User mentioned (0): @Timestamp
  • User mentioned (0): @EventSourcingHandler
  • User mentioned (0): @Timestamp
  • Low reputation (1):
Posted by: Yavuz Karan