19.3 Common Problems

The following section covers common problems developers encounter when using Micronaut.

Dependency injection is not working

The most common causes of Dependency Injection failing to work are not having the appropriate annotation processor configured, or an incorrectly configured IDE. See the section on Language Support for how to get setup in your language.

A NoSuchMethodError occurs loading beans (Groovy)

By default, Groovy imports classes in the groovy.lang package which includes a class called Singleton. This is an AST transformation annotation that makes your class a singleton by adding a private constructor and static retrieval method. This annotation is easily confused with the javax.inject.Singleton annotation used to define singleton beans in Micronaut. Make sure you use the correct annotation in your Groovy classes.

It is taking much longer to start my application than it should (*nix OS)

This is likely due to a bug related to java.net.InetAddress.getLocalHost() calls causing a long delay. The solution is to edit your /etc/hosts file to add an entry containing your host name. To find your host name, run hostname in a terminal. Then edit your /etc/hosts file to add or change entries like the example below, replacing <hostname> with your host name.

  1. 127.0.0.1 localhost <hostname>
  2. ::1 localhost <hostname>

To learn more about this issue, see this stackoverflow answer