Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8304881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:57:25+00:00 2026-06-08T17:57:25+00:00

It seems Guice is ignoring my @Provider methods of my module. I have a

  • 0

It seems Guice is ignoring my @Provider methods of my module.

I have a class MyModule like this:

public class MyModule extends AbstractModule {

    protected void configure() {

        bindInterceptor(Matchers.any(), Matchers.annotatedWith(Timed.class), new GuiceEnabledLoggingInterceptor());
        bind(OneClass.class).to(OneClassImpl.class);

        // And more binding lines...

    }

    @Provides
    public AnotherClassInApi provideMyClass() {
        return AnotherClassInApi.getInstance();
    }

    // And more @Provides methods

}

Main method is

public static void main(String[] args){
    ConfigHandler.getInstance().loadConfigWhenNotRunningInsideMicrocontainer();
    Injector INJECTOR = Guice.createInjector(new MyModule());
    // ...
}

In some other part of the project I have class AnotherClassInApi, which is a very standard singleton plus one method:

public class AnotherClassInApi {

    private static final AnotherClassInApi INSTANCE = new AnotherClassInApi();

    private AnotherClassInApi() { }

    // ... more methods

    public static AnotherClassInApi getInstance() {
        return INSTANCE;
    }
}

Well, I understand that should effectively bind any request for an AnotherClassInApi object to the getInstance() method, but it doesn’t work. Funny thing, a breakpoint in the @Provide method is never reached while debugging, but one in the configure method is reached. It seems guice is ignoring my provider annotation, and I think I’m following exactly what Guice guide says about @Provider, so I’m already stuck.

I’ve been googling around, but can’t find anything similar. Any help will be much appreciated.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:57:26+00:00Added an answer on June 8, 2026 at 5:57 pm

    The concept of Providers (and @Provides methods) is, that they are only called when actually needed. So unless you really use your Injector to create an instance that has an @Inject dependency, your Provider is not ignored, just not used (nor needed).

    You can monitor all configured bindings by using “injector.getAllBindings()“.

    java.util.Map,Binding> getAllBindings()

    Returns a snapshot
    of this injector’s bindings, both explicit and just-in-time. The
    returned map is immutable; it contains only the bindings that were
    present when getAllBindings() was invoked. Just-in-time bindings are
    only present if they have been requested at least once. Subsequent
    calls may return a map with additional just-in-time bindings. The
    returned map does not include bindings inherited from a parent
    injector, should one exist.

    This method is part of the Guice SPI and is intended for use by tools
    and extensions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that reads like this: class A { X x; A() {
Seems like i need some help with a project. I have a routine ,
We have guice set up as in the documentation and it seems to work
I have the following code public class Something { [Inject] public Configuration config {get;set;}
Looking at the Android tutorial on: http://developer.android.com/guide/topics/fundamentals/fragments.html ... it seems fragments have their layouts
Seems to be a problem that many people have, but all the answers I
Seems that This will be an easy question for you but this problem is
Seems like there should be... Right now it just seems like magic that you
Seems like cuke doesn't show the full error message (at least when problem occurs
I'm developing a small web framework using Guice. I have a Router object that,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.