Try to user QueryGateway with following code [koltin]
In controller:
`
@GetMapping("/all")
fun queryAllSystem() = monoQueryResult {
queryGateway.query("queryAll", "",List::class.java).get()
}
`
Query handler:
`
@Component
class SystemQueryHandler {
@Autowired
private lateinit var systemEntryRepository: SystemEntryRepository
@QueryHandler(queryName = "queryAll")
fun queryAll(): List<SystemEntry> {
return this.systemEntryRepository.findAll()
}
}
`
got exception when do request:
`
Caused by: org.axonframework.queryhandling.NoHandlerForQueryException: No handler found for queryAll with response type org.axonframework.queryhandling.responsetypes.InstanceResponseType@48e4bf1a
at org.axonframework.queryhandling.SimpleQueryBus.query(SimpleQueryBus.java:133) ~[axon-core-3.2.jar:3.2]
at org.axonframework.queryhandling.DefaultQueryGateway.query(DefaultQueryGateway.java:54) ~[axon-core-3.2.jar:3.2]
at org.axonframework.queryhandling.QueryGateway.query(QueryGateway.java:66) ~[axon-core-3.2.jar:3.2]
… 70 common frames omitted
I’m not a Kotlin expert, but to retrieve objects from the application context, you use MyClass::class.java whereas in the query, you use .javaClass. Could that make a difference?
Also, make sure that the component containing the query handlers is in a package that is scanned by Spring Boot.