Home » Eclipse Projects » Gemini » Gemini Blueprint and @Autowired(How can I use GB and annotation based DI)
Gemini Blueprint and @Autowired [message #720968] |
Wed, 31 August 2011 15:26 |
Nick Padilla Messages: 16 Registered: August 2011 Location: New Mexico |
Junior Member |
|
|
Hello All!
I have been trying to use the @Autowired inside a @Component. The annotations for my @Repository and @PersistentContext work as expected, however the @Autowired object is always NULL. I can see the objects in the ListableBeanFactory and can get at the objects using the ServiceLocator pattern. I am using Eclipse Indigo to build an RCP application and have integrated Spring 3.0.6 with Eclipse Gemini 1.0.0. Everything is working as expected, minus the ability to use @Autowired. I am guessing the problem lies in how I am attempting to use the annotation. I am trying to add it to an object that extends org.eclipse.core.runtime.PlatformObject, from my understanding Eclipse uses reflection to create some objects; could that be the problem? I am also using SpringWeaver 1.0.3, i had to do some work on the 1.0.2 version to get it working with the new environment. Weaving is working as expected, so does Lazy loading; just wanted to put that out there.
Is my assumption correct? Is there any way to get annotations working with the Eclipse RCP front end? Here are the relevant files:
Attached is the applicationContext.xml, couldn't add it to the post since I am not allowed to post links, even if they are in code tags.
Here is the java class that is trying to take advantage of the available DI:
@Component
public class MyModel extends PlatformObject {
@Autowired
private ICustomerDAO customerDAO;// = ServiceLocator.locateCurrent(ICustomerDAO.class);
public MyModel() {
}
public Object getRoot() {
return this;
}
public List<Customer> getCustomers() {
try {
List<Customer> customers = customerDAO.find(0,100);
return customers;
} catch (Throwable e) {
e.printStackTrace();
return new ArrayList<Customer>();
}
}
}
This is how the above class is trying to get created:
@Component
public class MyView extends ViewPart {
public static final String ID = "com.monstersoftwarellc.goldrush.view";
public static Logger LOG = Logger.getLogger(MyView.class);
@Autowired
private MyModel myModel;
private IAdapterFactory modelFactory = new ModelAdapterFactory();
private IAdapterFactory customerFactory = new CustomerAdapterFactory();
private IAdapterFactory titleFactory = new TransactionAdapterFactory();
private TreeViewer viewer;
class ViewContentProvider extends BaseWorkbenchContentProvider {
private DeferredTreeContentManager manager;
@SuppressWarnings("deprecation")
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
manager = new DeferredTreeContentManager(this, (AbstractTreeViewer) viewer);
}
public Object[] getChildren(Object parentElement) {
return manager.getChildren(parentElement);
}
public boolean hasChildren(Object element) {
return manager.mayHaveChildren(element);
}
}
public void createPartControl(Composite parent) {
IAdapterManager adapterManager = Platform.getAdapterManager();
adapterManager.registerAdapters(modelFactory, MyModel.class);
adapterManager.registerAdapters(customerFactory, Customer.class);
adapterManager.registerAdapters(titleFactory, POSEntry.class);
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new WorkbenchLabelProvider());
viewer.setInput(myModel.getRoot());
}
public void setFocus() {
viewer.getControl().setFocus();
}
@Override
public void dispose() {
IAdapterManager adapterManager = Platform.getAdapterManager();
adapterManager.unregisterAdapters(modelFactory);
adapterManager.unregisterAdapters(customerFactory);
adapterManager.unregisterAdapters(titleFactory);
super.dispose();
}
Here is the error that is being thrown when attempting to load MyView, by the RCP framework.
java.lang.NullPointerException
at com.monstersoftwarellc.goldrush.MyView.createPartControl(MyView.java:69)
at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:375)
at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:229)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
at org.eclipse.ui.internal.Perspective.showFastView(Perspective.java:2171)
at org.eclipse.ui.internal.Perspective.setActiveFastView(Perspective.java:1939)
at org.eclipse.ui.internal.Perspective.setActiveFastView(Perspective.java:1952)
at org.eclipse.ui.internal.Perspective.toggleFastView(Perspective.java:2367)
at org.eclipse.ui.internal.WorkbenchPage.toggleFastView(WorkbenchPage.java:3972)
at org.eclipse.ui.internal.ShowFastViewContribution.showView(ShowFastViewContribution.java:157)
at org.eclipse.ui.internal.ShowFastViewContribution.access$1(ShowFastViewContribution.java:155)
at org.eclipse.ui.internal.ShowFastViewContribution$3.widgetSelected(ShowFastViewContribution.java:138)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3588)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3209)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at com.monstersoftwarellc.goldrush.Application.start(Application.java:25)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Here is the start up log:
Configuration location:
file:/media/Data/workspaces/GoldRushStore/.metadata/.plugins/org.eclipse.pde.core/goldrush.product/
Configuration file:
file:/media/Data/workspaces/GoldRushStore/.metadata/.plugins/org.eclipse.pde.core/goldrush.product/config.ini loaded
Install location:
file:/media/Data/workspaces/GoldRushStore/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/
Framework located:
file:/media/Data/workspaces/GoldRushStore/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.eclipse.osgi_3.7.0.v20110613.jar
Loading extension: org.eclipse.equinox.weaving.hook
eclipse.properties not found
Framework classpath:
file:/media/Data/workspaces/GoldRushStore/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.eclipse.osgi_3.7.0.v20110613.jar
file:/media/Data/workspaces/GoldRushStore/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/
file:/media/Data/workspaces/GoldRushStore/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.eclipse.equinox.weaving.hook_1.0.100.v20110502.jar
Splash location:
/media/Data/workspaces/GoldRushStore/GoldRush/splash.bmp
Debug options:
file:/media/Data/workspaces/GoldRushStore/.metadata/.plugins/org.eclipse.pde.core/goldrush.product/.options loaded
osgi> Time to load bundles: 14
Aug 31, 2011 9:07:55 AM org.eclipse.gemini.blueprint.extender.internal.boot.ChainActivator <init>
INFO: Blueprint API detected; enabling Blueprint Container functionality
Aug 31, 2011 9:07:55 AM org.eclipse.gemini.blueprint.extender.internal.activator.ContextLoaderListener start
INFO: Starting [org.eclipse.gemini.blueprint.extender] bundle v.[1.0.0.RELEASE]
Aug 31, 2011 9:07:55 AM org.eclipse.gemini.blueprint.extender.internal.support.ExtenderConfiguration <init>
INFO: No custom extender configuration detected; using defaults...
Aug 31, 2011 9:07:55 AM org.springframework.scheduling.timer.TimerTaskExecutor afterPropertiesSet
INFO: Initializing Timer
Aug 31, 2011 9:07:55 AM org.eclipse.gemini.blueprint.extender.internal.activator.ContextLoaderListener start
INFO: Starting [org.eclipse.gemini.blueprint.extender] bundle v.[1.0.0.RELEASE]
Aug 31, 2011 9:07:55 AM org.eclipse.gemini.blueprint.extender.internal.support.ExtenderConfiguration <init>
INFO: No custom extender configuration detected; using defaults...
Aug 31, 2011 9:07:55 AM org.springframework.scheduling.timer.TimerTaskExecutor afterPropertiesSet
INFO: Initializing Timer
Starting application: 1386
Aug 31, 2011 9:07:55 AM org.eclipse.gemini.blueprint.extender.support.DefaultOsgiApplicationContextCreator createApplicationContext
INFO: Discovered configurations {osgibundle:/META-INF/spring/*.xml} in bundle [GoldRush (com.monstersoftwarellc.goldrush;singleton:=true)]
Aug 31, 2011 9:07:55 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing OsgiBundleXmlApplicationContext(bundle=com.monstersoftwarellc.goldrush, config=osgibundle:/META-INF/spring/*.xml): startup date [Wed Aug 31 09:07:55 MDT 2011]; root of context hierarchy
Aug 31, 2011 9:07:55 AM org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext unpublishContextAsOsgiService
INFO: Application Context service already unpublished
Aug 31, 2011 9:07:55 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from URL [bundleentry://1398.fwk1134979151/META-INF/spring/applicationContext.xml]
Aug 31, 2011 9:08:08 AM org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor stageOne
INFO: No outstanding OSGi service dependencies, completing initialization for OsgiBundleXmlApplicationContext(bundle=com.monstersoftwarellc.goldrush, config=osgibundle:/META-INF/spring/*.xml)
Aug 31, 2011 9:08:08 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1405ac5f: defining beans [dataSource,entityManagerFactory,transactionManager,defaultTransactionTemplate,requireNewTransactionTemplate,serviceLocator,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,myModel,customerDAO,employeeDAO,transactionDAO,myView]; root of factory hierarchy
Aug 31, 2011 9:08:09 AM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: org.apache.derby.jdbc.EmbeddedDriver
Aug 31, 2011 9:08:10 AM org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean createNativeEntityManagerFactory
INFO: Building JPA container EntityManagerFactory for persistence unit 'goldrush'
transformer added; Standard ClassFileTransformer wrapping JPA transformer: org.eclipse.persistence.internal.jpa.weaving.PersistenceWeaver@3e30e173
Aug 31, 2011 9:08:28 AM org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext publishContextAsOsgiServiceIfNecessary
INFO: Publishing application context as OSGi service with properties {org.eclipse.gemini.blueprint.context.service.name=com.monstersoftwarellc.goldrush, org.springframework.context.service.name=com.monstersoftwarellc.goldrush, Bundle-SymbolicName=com.monstersoftwarellc.goldrush, Bundle-Version=1.0.0.qualifier}
Aug 31, 2011 9:08:28 AM org.eclipse.gemini.blueprint.extender.internal.support.DefaultOsgiBundleApplicationContextListener onOsgiApplicationEvent
INFO: Application context successfully refreshed (OsgiBundleXmlApplicationContext(bundle=com.monstersoftwarellc.goldrush, config=osgibundle:/META-INF/spring/*.xml))
Application Started: 45553
Please let me know what I am doing wrong, or if this is just a current limitation of the frameworks. If so is there a work around to get this working using annotations? If any more details are needed please let me know.
|
|
| | |
Goto Forum:
Current Time: Fri Apr 26 16:16:26 GMT 2024
Powered by FUDForum. Page generated in 0.03929 seconds
|