Eclipse:javax.annotation 未调用 PostConstruct
Eclipse: javax.annotation PostConstruct is not called
我正在使用 Fedora 29 并试图通过创建一个新的插件项目并使用 "View contribution using 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 的罐子之后(它被称为 javax.annotation-api 而不是 javax.annotation...)我发现它们有一个符号 link 到 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
在spring中你需要在application context中添加这一行,希望能帮到你
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
我正在使用 Fedora 29 并试图通过创建一个新的插件项目并使用 "View contribution using 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 的罐子之后(它被称为 javax.annotation-api 而不是 javax.annotation...)我发现它们有一个符号 link 到 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
在spring中你需要在application context中添加这一行,希望能帮到你
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />