简体   繁体   English

为什么@Inject永远不会在我的抽象类中被调用

[英]Why does the @Inject never get called in my abstract class

I have the following scenario shown below. 我有以下情况如下所示。 When I run the class in a debugger the @Inject never hits for myInjectMethod . 当我在调试器中运行的类的@Inject从未命中myInjectMethod If I move the myInjectMethod to MyService it works. 如果我将myInjectMethod移动到MyService就行了。 Why is this happening? 为什么会这样?

@Singleton
@Creatable
public class MyService extends MyBaseService {

    @Inject
    public MyService(final IEclipseContext context) {
        context.set(MyService.class.getName(), this);
    }
}

abstract class MyBaseService {
    @Inject
    public void myInjectMethod(@Preference(nodePath = "MyPreferenceName", 
           value = "MyPreferenceValue") final boolean isSomething) {
         // Why do I never get here when running the debugger?
         System.out.println("Hello");
    }
}

Try moving the abstract class to its own file and making it public. 尝试将抽象类移动到自己的文件并将其公开。

Which DI framework are you using? 你使用哪个DI框架? It might be that it doesn't support looking in super classes. 它可能不支持查看超类。

It seems the @Inject will not fire if the abstract class is package level. 如果抽象类是包级别的话,似乎@Inject不会触发。 When I changed the abstract class to public, it started working. 当我将抽象类更改为public时,它开始工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM