DEV Community

Eric Helgeson
Eric Helgeson

Posted on

Wiring Micronaut beans in Grails Services

Micronaut beans in Grails 4 are wired by type - not the default Grails users are used to using - wire by name.

For example if we have a micronaut-http-client bean named MyRestClient under src/main/groovy/<package>/MyRestClient.groovy and we want to wire it into the Grails service SomeService we must supply the type:

class SomeService {
    // ❌ wont work, as Grails will look for a bean name that wont exist.
    // def myRestClient

    // ✅ Works!
    MyRestClient myRestClient
}

Tested on Grails 4.0.2.

Top comments (0)