No handler found for query

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

`

what I know is the response type not matched

how to fix it?

Hi!

As the second argument to the QueryGateway’s query method, instead of “List::class.java”, you should use:

ResponseTypes.multipleInstancesOf(SystemEntry::class.java)

with ResponseTypes imported as

import org.axonframework.queryhandling.responsetypes.ResponseTypes

Kind regards,

it works

thanks

Hi,

I have the same issue.

Here is main application:

`

@SpringBootApplication
open class MainApplication {

    companion object {

        @JvmStatic
        fun main(args: Array<String>) {
            var configurableApplicationContext = SpringApplication.run(MainApplication::class.java, *args)

            val queryGateway = configurableApplicationContext.getBean(QueryGateway::class.java)
            val commandGateway = configurableApplicationContext.getBean(CommandGateway::class.java)

            commandGateway.sendAndWait<CreateDeviceCmd>(CreateDeviceCmd(UUID.randomUUID().toString(), "WTKSSJJ", 122))

            queryGateway.query(FetchDevicesQuery(2), ResponseTypes.instanceOf(String.javaClass)).get()
        }
    }
}

`

And here is query handler:

`

@Component
class DeviceQueryHandler {

    @QueryHandler
    fun handle(query: FetchDevicesQuery): String {
        return "test"
    }

}

`

CommandGateway works fine but for some reason QueryHandler is not visible and i’m getting NoHandlerForQueryException for FetchDevicesQuery.

Any tip?

Hi,

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.

Hope this helps.
Allard