簡體   English   中英

Eclipse:未調用 javax.annotation PostConstruct

[英]Eclipse: javax.annotation PostConstruct is not called

我正在使用 Fedora 29 並嘗試通過創建一個新的插件項目並使用“使用 4.X API 查看貢獻”模板來嘗試一個簡單的插件示例。

我提供了以下系統屬性:

-Dorg.eclipse.e4.core.di.debug=true

在我的 eclipse 下的 VM 參數中。

啟用該調試后,我收到以下消息:

!MESSAGE Possbible annotation mismatch: method "public void hello.parts.SampleView.createPartControl(org.eclipse.swt.widgets.Composite)" annotated with "javax.annotation-api:1.2.0:javax.annotation.PostConstruct" but was looking for "javax.annotation.PostConstruct [via bootstrap classloader]"

此錯誤消息是什么意思,我該如何解決?

這是包含 PostConstruct 注釋的 eclipse 插件示例的片段。

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

public class SampleView {
    private Label myLabelInView;

    @PostConstruct
    public void createPartControl(Composite parent) {
        System.out.println("Enter in SampleE4View postConstruct");

        myLabelInView = new Label(parent, SWT.BORDER);
        myLabelInView.setText("This is a sample E4 view");

    }

編輯:

Manifest.mf 文件:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Hello
Bundle-SymbolicName: hello;singleton:=true
Bundle-Version: 1.0.0.qualifier
Require-Bundle: javax.inject,
 org.eclipse.osgi,
 org.eclipse.jface,
 org.eclipse.e4.ui.model.workbench,
 org.eclipse.e4.ui.di,
 org.eclipse.e4.ui.services,
 org.eclipse.e4.core.di.annotations
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: hello
Import-Package: javax.annotation

編輯2:

在檢查了 javax.annotation 的 jars(它被稱為 javax.annotation-api 而不是 javax.annotation...)后,我發現它們有一個指向 glassfish 實現的符號鏈接:

/usr/lib/eclipse/plugins/javax.annotation-api_1.2.0.jar -> /usr/share/java/glassfish-annotation-api.jar
/usr/lib/eclipse/plugins/javax.el-api_3.0.0.jar -> /usr/share/java/glassfish-el-api.jar
/usr/lib/eclipse/plugins/javax.inject_1.0.0.v20091030.jar -> /usr/share/java/atinject.jar
/usr/lib/eclipse/plugins/javax.servlet-api_3.1.0.jar -> /usr/share/java/glassfish-servlet-api.jar
/usr/lib/eclipse/plugins/javax.servlet.jsp_2.3.2.b01.jar -> /usr/share/java/glassfish-jsp-api/javax.servlet.jsp-api.jar

看起來Import-Package選擇了錯誤的插件。 還應該有一個正確的javax.annotation插件。 嘗試將javax.annotation添加到Require-Bundle列表以強制使用它:

Require-Bundle: javax.inject,
 javax.annotation,
 org.eclipse.osgi,
 org.eclipse.jface,
 org.eclipse.e4.ui.model.workbench,
 org.eclipse.e4.ui.di,
 org.eclipse.e4.ui.services,
 org.eclipse.e4.core.di.annotations

在春天你需要在應用程序上下文中添加這一行,我希望能幫助你

<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM