Reputation: 1031
I am getting NoHandlerForCommandException: No Handler for command while trying to use Axon framework with Spring boot.
Below are my Java files :
The Rest controller ->
@RestController
@RequestMapping("/product")
public class ProductController {
@Autowired
private CommandGateway gateway;
@PostMapping
public ResponseEntity createProduct(@RequestBody CreateProductModel model) {
CreateProductCommand command=CreateProductCommand.builder()
.price("$123")
.productId(UUID.randomUUID().toString())
.product("Shoe")
.build();
String s=gateway.sendAndWait(command);
return new ResponseEntity<String>(HttpStatus.CREATED);
}
The ProductCreatedEvent object ->
import lombok.Data;
@Data
public class ProductCreatedEvent {
@TargetAggregateIdentifier
private String productId;
private String product;
private String price ;
}
The command class CreateProductCommand ->
@Builder
@Data
public class CreateProductCommand {
@TargetAggregateIdentifier
private final String productId;
private final String product;
private final String price ;
}
The Aggregate class ->
@Aggregate
public class ProductAggregate {
@AggregateIdentifier
private String productId;
private String product;
private String price ;
public ProductAggregate() {
}
@CommandHandler
public ProductAggregate(CreateProductCommand command) {
//TODO: Validation logic can be handled here
ProductCreatedEvent event=new ProductCreatedEvent();
BeanUtils.copyProperties(command, event);
AggregateLifecycle.apply(event);
}
@EventSourcingHandler
public void on(ProductCreatedEvent event) {
this.price=event.getPrice();
this.productId=event.getProductId();
this.product=event.getProduct();
}
}
Upvotes: 0
Views: 509
Reputation: 21
You should not use the annotation TargetAggregateIdentifier in The ProductCreatedEvent class
Upvotes: 0