'Micronaut declarative http-client not injected in Grails 5.1.6 controllers / services
I migrated an app from Grails 4.0.0 to Grails 5.1.6, it is using the Micronaut declarative client to make requests to an external API. When I run it with grails run-app
it works fine, but when I generate the war with grails war
and deploy it to a Tomcat container the Micronaut client is not injected correctly, when a controller action is called it throws the exception:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'example.grails.HomeController': Unsatisfied dependency expressed through field 'appForgeClient'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'example.grails.GrailsAppForgeClient' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Do you have an idea why it is not injected / found?
I am using:
- Grails 5.1.6
- openjdk 11.0.14.1
- tomcat:8.5-jdk11-openjdk
Sample app https://github.com/solaechea/SampleMicronautClientApp
build.gradle
compileOnly "io.micronaut:micronaut-inject-groovy"
implementation 'io.micronaut:micronaut-http-client'
application.yml
micronaut:
http:
services:
backend:
urls:
- https://start.grails.org
path: /
read-timeout: 1m
read-idle-timeout: 1m
max-content-length: 1mb
GrailsAppForgeClient.groovy (Declarative client)
import io.micronaut.http.annotation.Get
import io.micronaut.http.client.annotation.Client
@Client("backend")
interface GrailsAppForgeClient {
@Get("/{version}/profiles")
List<Map> profiles(String version)
}
HomeController.groovy
import grails.converters.JSON
import org.springframework.beans.factory.annotation.Autowired
class HomeController {
@Autowired GrailsAppForgeClient appForgeClient
def profiles() {
String grailsVersion = '5.1.6'
render(appForgeClient.profiles(grailsVersion) as JSON)
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|