Micronaut-core: Exception Trying To Get EmbeddedServerInstance

Created on 11 Apr 2019  路  5Comments  路  Source: micronaut-projects/micronaut-core

Task List

  • [x] Steps to reproduce provided
  • [x] Stacktrace (if present) provided
  • [x] Example that reproduces the problem uploaded to Github
  • [x] Full description of the issue provided (see below)

Steps to Reproduce

  1. Create a new application
  2. In a controller method, paste the code from the documentation located in the section titled "Using Cloud Instance Metadata" (https://docs.micronaut.io/latest/guide/index.html#cloudConfiguration)

The code in question inside my controller method:

@Get("/")
ConvertibleValues<String> index() {
    EmbeddedServerInstance embeddedServerInstance = applicationContext.getBean(EmbeddedServerInstance.class)
    return embeddedServerInstance.getMetadata()
}

  1. Run the app and invoke the controller method.

Expected Behaviour

The controller method should return the embedded server instance metadata.

Actual Behaviour

I receive an exception when trying to retrieve the EmbeddedServerInstance bean:

Unexpected error occurred: Error instantiating bean of type  [io.micronaut.http.server.netty.NettyEmbeddedServerInstance]

Message: Missing bean arguments for type: io.micronaut.http.server.netty.NettyEmbeddedServerInstance. Requires arguments: String id,NettyHttpServer nettyHttpServer

io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type  [io.micronaut.http.server.netty.NettyEmbeddedServerInstance]

Message: Missing bean arguments for type: io.micronaut.http.server.netty.NettyEmbeddedServerInstance. Requires arguments: String id,NettyHttpServer nettyHttpServer

    at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1441)
    at io.micronaut.context.DefaultBeanContext.getScopedBeanForDefinition(DefaultBeanContext.java:1895)
    at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1807)
    at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1785)
    at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:561)
    at codes.recursive.compute.TestController.index(TestController.groovy:25)
    at codes.recursive.compute.$TestControllerDefinition$$exec1.invokeInternal(Unknown Source)
    at io.micronaut.context.AbstractExecutableMethod.invoke(AbstractExecutableMethod.java:144)
    at io.micronaut.context.DefaultBeanContext$BeanExecutionHandle.invoke(DefaultBeanContext.java:2618)
    at io.micronaut.web.router.AbstractRouteMatch.execute(AbstractRouteMatch.java:236)
    at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:122)
    at io.micronaut.http.server.netty.RoutingInBoundHandler.lambda$buildResultEmitter$16(RoutingInBoundHandler.java:1324)
    at io.reactivex.internal.operators.flowable.FlowableCreate.subscribeActual(FlowableCreate.java:71)
    at io.reactivex.Flowable.subscribe(Flowable.java:14805)
    at io.reactivex.Flowable.subscribe(Flowable.java:14752)
    at io.micronaut.reactive.rxjava2.RxInstrumentedFlowable.subscribeActual(RxInstrumentedFlowable.java:68)
    at io.reactivex.Flowable.subscribe(Flowable.java:14805)
    at io.reactivex.internal.operators.flowable.FlowableMap.subscribeActual(FlowableMap.java:37)
    at io.reactivex.Flowable.subscribe(Flowable.java:14805)
    at io.reactivex.Flowable.subscribe(Flowable.java:14752)
    at io.micronaut.reactive.rxjava2.RxInstrumentedFlowable.subscribeActual(RxInstrumentedFlowable.java:68)
    at io.reactivex.Flowable.subscribe(Flowable.java:14805)
    at io.reactivex.internal.operators.flowable.FlowableSwitchIfEmpty.subscribeActual(FlowableSwitchIfEmpty.java:32)
    at io.reactivex.Flowable.subscribe(Flowable.java:14805)
    at io.reactivex.Flowable.subscribe(Flowable.java:14752)
    at io.micronaut.reactive.rxjava2.RxInstrumentedFlowable.subscribeActual(RxInstrumentedFlowable.java:68)
    at io.reactivex.Flowable.subscribe(Flowable.java:14805)
    at io.reactivex.Flowable.subscribe(Flowable.java:14755)
    at io.micronaut.http.context.ServerRequestTracingPublisher.lambda$subscribe$0(ServerRequestTracingPublisher.java:52)
    at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:52)
    at io.micronaut.http.context.ServerRequestTracingPublisher.subscribe(ServerRequestTracingPublisher.java:52)
    at io.reactivex.internal.operators.flowable.FlowableFromPublisher.subscribeActual(FlowableFromPublisher.java:29)
    at io.reactivex.Flowable.subscribe(Flowable.java:14805)
    at io.reactivex.Flowable.subscribe(Flowable.java:14752)
    at io.micronaut.reactive.rxjava2.RxInstrumentedFlowable.subscribeActual(RxInstrumentedFlowable.java:68)
    at io.reactivex.Flowable.subscribe(Flowable.java:14805)
    at io.reactivex.Flowable.subscribe(Flowable.java:14752)
    at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
    at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker$BooleanRunnable.run(ExecutorScheduler.java:288)
    at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker.run(ExecutorScheduler.java:253)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.base/java.lang.Thread.run(Thread.java:844)

Environment Information

  • Operating System: MacOS High Sierra
  • Micronaut Version: 1.1.0RC2
  • JDK Version: 1.8.0_201

Example Application

workaround available under consideration docs

All 5 comments

Additional info: I'd love to test this out so that I can (attempt) to contribute an OracleCloudComputeInstanceMetadata implementation to the project. :)

I'm not sure if the docs or implementation is incorrect, however you could still get the instance metadata.

You could listen for the ServiceStartedEvent in your controller and set a field on the controller.

@Controller
public class Controller {

    private ServiceInstance serviceInstance;

    @EventListener
    void onServiceStarted(ServiceStartedEvent event) {
        serviceInstance = event.getSource();
    }

}

the documentation is incorrect, you currently need to use an event listener for this case.

Thanks - I'll give that a shot.

Follow up for anyone finding this via Google search:

Confirmed way to obtain metadata:

@CompileStatic
@Controller("/test")
class TestController {

    final static Logger logger = LoggerFactory.getLogger(TestController.class)
    private ServiceInstance serviceInstance

    @EventListener
    void onServiceStarted(ServiceStartedEvent event) {
        serviceInstance = event.getSource()
    }

    @Get("/")
    ConvertibleValues<String> index() {
        return serviceInstance.metadata
    }
}

Deployed to an Amazon EC2 instance results in:

image

Was this page helpful?
0 / 5 - 0 ratings