Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我做了这样的事情
bindEagerSingleton(MyClass.class);
我可以做这样的事情吗
@SomeAnnotation public class MyClass {}
谢谢!
正如评论中所讨论的,没有这样的注释,你是正确的,类路径扫描是罪魁祸首:Guice 不进行类路径扫描,所以即使有@EagerSingleton注释,Guice 仍然不会遇到对类的引用(或其完全限定的类名),直到您提出要求。到那时,它就不再渴望了。
@EagerSingleton