question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Koin cannot find beans on Ktor when autoreload is active

See original GitHub issue

Steps to reproduce :

  • Checkout the ktor-hellowebapp from the samples
  • Add these lines in the deployment block of application.conf
        autoreload = true
        watch = [ sample ]
  • Run the app

Stacktrace :

> Task :run
(KOIN) :: [INFO] :: [context] create
(KOIN) :: [INFO] :: [module] declare Bean[class=org.koin.sample.BusinessService]
(KOIN) :: [INFO] :: [modules] loaded 1 definitions
(KOIN) :: [INFO] :: [properties] load koin.properties
(KOIN) :: [INFO] :: [properties] load extras properties : 2
(KOIN) :: [DEBUG] :: [Property] add properties 2
2018-03-13 10:59:17.640 [main] TRACE Application - {
    # application.conf @ file:/Users/tarek/Sources/github/koin-samples/samples/ktor-hellowebapp/build/resources/main/application.conf: 8
    "application" : {
        # application.conf @ file:/Users/tarek/Sources/github/koin-samples/samples/ktor-hellowebapp/build/resources/main/application.conf: 9
        "modules" : [
            # application.conf @ file:/Users/tarek/Sources/github/koin-samples/samples/ktor-hellowebapp/build/resources/main/application.conf: 10
            "org.koin.sample.KoinApplicationKt.main",
            # application.conf @ file:/Users/tarek/Sources/github/koin-samples/samples/ktor-hellowebapp/build/resources/main/application.conf: 11
            "org.koin.sample.JobRoutesKt.jobRoutes"
        ]
    },
    # application.conf @ file:/Users/tarek/Sources/github/koin-samples/samples/ktor-hellowebapp/build/resources/main/application.conf: 2
    "deployment" : {
        # application.conf @ file:/Users/tarek/Sources/github/koin-samples/samples/ktor-hellowebapp/build/resources/main/application.conf: 4
        "autoreload" : true,
        # application.conf @ file:/Users/tarek/Sources/github/koin-samples/samples/ktor-hellowebapp/build/resources/main/application.conf: 3
        "port" : 8080,
        # application.conf @ file:/Users/tarek/Sources/github/koin-samples/samples/ktor-hellowebapp/build/resources/main/application.conf: 5
        "watch" : [
            # application.conf @ file:/Users/tarek/Sources/github/koin-samples/samples/ktor-hellowebapp/build/resources/main/application.conf: 5
            "sample"
        ]
    },
    # Content hidden
    "security" : "***"
}

2018-03-13 10:59:17.740 [main] DEBUG Application - Java Home: /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home
2018-03-13 10:59:17.740 [main] DEBUG Application - Class Loader: sun.misc.Launcher$AppClassLoader@15db9742: [/* removed */]
2018-03-13 10:59:17.757 [main] DEBUG Application - Watching /Users/tarek/Sources/github/koin-samples/samples/ktor-hellowebapp/build/classes/kotlin/main/org for changes.
2018-03-13 10:59:17.757 [main] DEBUG Application - Watching /Users/tarek/Sources/github/koin-samples/samples/ktor-hellowebapp/build/resources/main for changes.
2018-03-13 10:59:17.757 [main] DEBUG Application - Watching /Users/tarek/Sources/github/koin-samples/samples/ktor-hellowebapp/build/classes/kotlin/main for changes.
2018-03-13 10:59:17.757 [main] DEBUG Application - Watching /Users/tarek/Sources/github/koin-samples/samples/ktor-hellowebapp/build/classes/kotlin/main/org/koin for changes.
2018-03-13 10:59:17.757 [main] DEBUG Application - Watching /Users/tarek/Sources/github/koin-samples/samples/ktor-hellowebapp/build/classes/kotlin/main/META-INF for changes.
2018-03-13 10:59:17.757 [main] DEBUG Application - Watching /Users/tarek/Sources/github/koin-samples/samples/ktor-hellowebapp/build/classes/kotlin/main/org/koin/sample for changes.
2018-03-13 10:59:18.124 [main] TRACE Application - Application started: io.ktor.application.Application@928763c
2018-03-13 10:59:23.849 [nettyCallPool-4-1] ERROR Application - Unhandled: GET - /bye
org.koin.error.NoBeanDefFoundException: No definition found to resolve type 'org.koin.sample.BusinessService'. Check your module definition
        at org.koin.KoinContext.getVisibleBeanDefinition(KoinContext.kt:119)
        at org.koin.KoinContext.resolveInstance(KoinContext.kt:77)
        at org.koin.sample.JobRoutesKt$jobRoutes$$inlined$inject$2.invoke(KtorApplicationExt.kt:82)
        at kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:131)
        at org.koin.sample.JobRoutesKt$jobRoutes$1$4.doResume(JobRoutes.kt:43)
        at org.koin.sample.JobRoutesKt$jobRoutes$1$4.invoke(JobRoutes.kt)
        at org.koin.sample.JobRoutesKt$jobRoutes$1$4.invoke(JobRoutes.kt)
        at io.ktor.pipeline.PipelineContext.proceed(PipelineContext.kt:49)
        at io.ktor.pipeline.Pipeline.execute(Pipeline.kt:22)
        at io.ktor.routing.Routing.executeResult(Routing.kt:93)
        at io.ktor.routing.Routing.interceptor(Routing.kt:19)
        at io.ktor.routing.Routing$Feature$install$1.doResume(Routing.kt:60)
        at io.ktor.routing.Routing$Feature$install$1.invoke(Routing.kt)
        at io.ktor.routing.Routing$Feature$install$1.invoke(Routing.kt:45)
        at io.ktor.pipeline.PipelineContext.proceed(PipelineContext.kt:49)
        at io.ktor.features.CallLogging$Feature$install$1.doResume(CallLogging.kt:69)
        at io.ktor.features.CallLogging$Feature$install$1.invoke(CallLogging.kt)
        at io.ktor.features.CallLogging$Feature$install$1.invoke(CallLogging.kt:61)
        at io.ktor.pipeline.PipelineContext.proceed(PipelineContext.kt:49)
        at io.ktor.pipeline.Pipeline.execute(Pipeline.kt:22)
        at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.doResume(DefaultEnginePipeline.kt:66)
        at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invoke(DefaultEnginePipeline.kt)
        at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invoke(DefaultEnginePipeline.kt)
        at io.ktor.pipeline.PipelineContext.proceed(PipelineContext.kt:49)
        at io.ktor.pipeline.Pipeline.execute(Pipeline.kt:22)
        at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.doResume(NettyApplicationCallHandler.kt:27)
        at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invoke(NettyApplicationCallHandler.kt)
        at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invoke(NettyApplicationCallHandler.kt:10)
        at kotlinx.coroutines.experimental.intrinsics.UndispatchedKt.startCoroutineUndispatched(Undispatched.kt:44)
        at kotlinx.coroutines.experimental.CoroutineStart.invoke(CoroutineStart.kt:113)
        at kotlinx.coroutines.experimental.AbstractCoroutine.start(AbstractCoroutine.kt:161)
        at kotlinx.coroutines.experimental.BuildersKt.launch(Builders.kt:68)
        at kotlinx.coroutines.experimental.BuildersKt.launch$default(Builders.kt:61)
        at io.ktor.server.netty.NettyApplicationCallHandler.handleRequest(NettyApplicationCallHandler.kt:22)
        at io.ktor.server.netty.NettyApplicationCallHandler.channelRead(NettyApplicationCallHandler.kt:16)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:38)
        at io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:353)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:748)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
arnaudgiulianicommented, Mar 14, 2018

Hello,

Ok. let us check with autoreload.

1reaction
arnaudgiulianicommented, Aug 10, 2018

And then, no need to start Koin from outside Ktor. Works also for unit test 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Auto-reload | Ktor
Ktor allows you to overcome this limitation by using Auto-reload, which reloads application classes on code changes and provides a fast ...
Read more >
No bean found when using koin in non-activity class
I am trying to use work manager and use Koin to get some dependencies I have setup. My work manager extends KoinComponent which...
Read more >
Not only Spring Boot: a review of alternatives
Not only Spring Boot: a review of alternatives · Preface · Prerequisites · Creating an application from scratch · Helidon service · Ktor...
Read more >
Review of Microservices Frameworks: A Look at Spring Boot ...
In this article, we will be considering alternatives to the Spring Boot framework for creating and building microservices in Java and ...
Read more >
Microservice Framework:Who Else Can You Choose if You ...
Ktor service. The framework is written and designed for Kotlin. Like Helidon SE, Ktor doesn't have DI out of the box, so Koin...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found