Create a class extending AbstractModule

Create a class as follows:

Figure 1. Skeleton Guice Module
package curam.mypackage;

import com.google.inject.AbstractModule;

/**
 * Contains my Guice bindings.
 */
public class MyModule extends AbstractModule {

  /**
   * {@inheritDoc}
   */
  @Override
  public void configure() {
    // no explicit bindings
  }
}

You can now add new Guice "bindings" to the configure method to override default implementations:

@Override
  public void configure() {
    bind(MyNewEntity.class).to(MyCustomNewEntityImpl.class);
  }

This configuration will cause Guice to dish up an instances of MyCustomNewEntityImpl instead of the default implementation (MyNewEntityImpl), whenever an MNewEntity interface instance is @Injected.

You will also add configuration code if your application uses events (see Events).

Important: Each interface can only be bound to a single implementation. If the set of runtime Guice modules attempts to bind the same interface more than once, Guice will raise a runtime exception.

As such, code which is delivered to customers should not use this mechanism to bind an interface to an implementation in any situation where the customer should be permitted to specify their own binding for the interface.