Wiring Micronaut beans in Grails Services

erichelgeson

Eric Helgeson

Posted on April 2, 2020

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.

💖 💪 🙅 🚩
erichelgeson
Eric Helgeson

Posted on April 2, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related