Search code examples
javadependency-injectionjavabeansquarkus

How to register a bean in Quarkus Main method


I have a Quarkus application that works in batch mode. I have a QuarkusMain class, with a method that implements QuarkusApplication interface.

That method is a static method, so I'm not able to inject Beans because they have a null value.

What is the way to inject Beans in Quarkus from a static method in a QuarkusMain class?

Thanks.


Solution

  • Are you really after creating beans in the static method, or more just after how to startup Quarkus ?

    In main method the only thing you need to do is call Quarkus.run(YourMain.class, args); which then will make YourMain class a bean and in here allow @Inject.

    You can also use picocli which also ends up with a class you can use @Inject.

    Example of that I have here: https://github.com/jbangdev/jbang-catalog/blob/master/catalog2readme.java