Micronaut - Add Controller from external library

13 Views Asked by At

I'm trying to use Micronaut as a container of rest endpoints located in external jars.

module1.jar

-- Module1Controller

-- .. other controllers

module2.jar

-- Module2Controller

-- ... other controllers

app-container.jar

-- Application.java (Micronaut Application)

import io.micronaut.context.ApplicationContext;
import io.micronaut.context.annotation.Import;
import io.micronaut.runtime.Micronaut;

@Import(
    packages = {
        "com.example.module1", "com.example.module2"
    },
    annotated = "*"
)
public class Application {

    public static void main(String[] args) {
        ApplicationContext applicationContext = Micronaut.run(Application.class, args);
    }
}
@Controller("/module1")
public class Module1Controller {

    @Get(produces = {"text/plain"})
    public String index() {
        return "Hello Module 1!";
    }
}

but when I start the application it gaves me a 404 navigating http://localhost:8080/module1.

The weird part is that the Module1Controller seems correctly injected if a try to print it in the console:


public class Application {

    public static void main(String[] args) {
        ApplicationContext applicationContext = Micronaut.run(Application.class, args);

        Module1Controller bean = applicationContext.getBean(Module1Controller .class);
        System.out.println(bean.index());

    }
}

what I'm doing wrong?

I'm expecting that Controllers that comes from external library and imported using the @Import annotation are injected in the http layer of Micronaut

0

There are 0 best solutions below