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

问题描述 投票:0回答:2

我有以下情况如下所示。当我在调试器中运行该类时,@Inject永远不会命中myInjectMethod。如果我将myInjectMethod移动到MyService它的工作原理。为什么会这样?

@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");
    }
}
java rcp e4
2个回答
0
投票

尝试将抽象类移动到自己的文件并将其公开。

你使用哪个DI框架?它可能不支持查看超类。


0
投票

如果抽象类是包级别的话,似乎@Inject不会触发。当我将抽象类更改为public时,它开始工作。

© www.soinside.com 2019 - 2024. All rights reserved.