【问题标题】:E4 doesn´t invoke my @PostConstruct-MethodE4 不调用我的@PostConstruct-Method
【发布时间】:2016-02-10 08:07:06
【问题描述】:

我在将 E3-RCP-Application 迁移到 E4 时遇到问题。 在那里我得到了 3 个部分。 2 与 Lars Vogel 的示例内容(http://www.vogella.com/tutorials/EclipseRCP/article.html#plugin_creatinge4“使用 SWT 电源小部件”)进行测试并与我的部分进行比较。

长话短说(呃):应该创建视图内容的方法,标记为@PostConstruct,不会被调用,但 SampleContent 的 @PostConstruct 会。这可能有什么原因? MyView 的构造函数被调用。

我的视图结构如下:

Many Imports

public class MyView1 implements IRefreshableView, ISomeListener {

a lot of fields, some are injected...

public MyView1()  {
        reference to the Activator-Class to get some item.
    }

@PostConstruct
public void createControls(Composite parent) {
        createViewToolbar();``

and much more Part Creation stuff that won´t be invoked...

}

much more methods
@Focus
    public void setFocus() {
        if (treeViewer.getTree().isVisible()) {
            treeViewer.getTree().setFocus();
        } else {
            mainForm.setFocus();
        }
    }

}

new class definition in the same file. 

END

很抱歉没有发布整个代码,它就像 1000 行一样长:/

我在 Win7 上使用 Mars 4.5.1

【问题讨论】:

  • 这个类是如何创建的?它是否列为 Application.e4xmi 的一部分?
  • 没错。类 URI 指向 MyView1 类。以及ID是一样的
  • 可能注入器在您未显示的某些字段上遇到问题。查看工作区.metadata目录下的.log文件,看看是否有更详细的消息
  • 不要担心代表,帮助是主要的。
  • 我添加了一个答案来帮助其他有类似问题的人。

标签: eclipse eclipse-plugin eclipse-rcp e4


【解决方案1】:

@PostConstruct 无法运行的一个原因是直接注入代码无法找到在字段中注入的对象(或注入的构造函数)。如果发生这种情况,注入器只会记录一个错误并停止。

错误记录在工作区“.metadata”目录中的“.log”文件中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-14
    • 2013-08-12
    • 2014-10-21
    • 1970-01-01
    • 2015-06-29
    • 2017-08-02
    • 1970-01-01
    • 2011-12-23
    相关资源
    最近更新 更多