Roman T
Roman T

Reputation: 2000

Loading @Singleton Beans from external jar

I'm trying to load into my micronaut CLI application (cli.jar) some classes from an external jar, annotated with @singleton in hope that they will be injected in the application. That doesn't happen, even though the classes actually packaged (shadowed) in the cli.jar. I tried to see with java -verbose, whether the classes in the class loader and they are not.

Can it work with micronaut?

Upvotes: 0

Views: 1094

Answers (2)

Roman T
Roman T

Reputation: 2000

Here is the solution according to Graeme's hint. Here is a build.gradle with the working setup:

plugins {
    id 'java'
    id "io.spring.dependency-management" version "1.0.6.RELEASE"
}

group 'xyz.transformercli'
version '1.0-SNAPSHOT'

sourceCompatibility = 11

repositories {
    mavenCentral()
}

dependencyManagement {
    imports {
        mavenBom 'io.micronaut:micronaut-bom:1.0.3'
    }
}

dependencies {
    annotationProcessor "io.micronaut:micronaut-inject-java"
    //my jar with base classes
    compile files('libs/transformer-cli-0.1.jar')
    compile "io.micronaut:micronaut-inject"
}

Upvotes: 1

Graeme Rocher
Graeme Rocher

Reputation: 7985

Make sure the external JAR also has annotation processing configured so that the classes annotated with @Singleton produce the appropriate bean metadata

Upvotes: 2

Related Questions