Hello,
I am having applicationContext with one bean definition like below:
Code:
<beans>
<bean id="test" name="test" class="com.jpmorgan.rubi.nukeeasy.service.Test"></bean>
</beans>
When I try to get bean using Eclipse RCP UI, though applicationContext.xml is getting loaded, I am getting "NoSuchBeanDefinitionException" when I try to get bean through this applicationContext.
Giving below the stack trace:
Code:
Mar 13, 2013 2:32:52 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@b6548: display name [org.springframework.context.support.ClassPathXmlApplicationContext@b6548]; startup date [Wed Mar 13 14:32:52 IST 2013]; root of context hierarchy
Mar 13, 2013 2:32:52 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@b6548]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1efb4be
Mar 13, 2013 2:32:52 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'test' is defined
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1efb4be: defining beans []; root of factory hierarchy
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:391)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:999)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:883)
at com.jpmorgan.rubi.nukeeasy.service.NukeEasyService.nukeTasks(NukeEasyService.java:30)
at com.jpmorgan.rubi.nukeeasy.ui.View$3.widgetSelected(View.java:194)
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:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at com.jpmorgan.rubi.nukeeasy.ui.Application.start(Application.java:20)
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:585)
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)
The RCP code to load applicationContext is written in its Activator.java as shown below:
Code:
// RCP start method
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
if (appContext == null) {
try {
// appContext = new FileSystemXmlApplicationContext("classpath*:applicationContext.xml");
appContext = new ClassPathXmlApplicationContext("classpath*:applicationContext.xml");
} catch (Exception e) {
e.printStackTrace();
}
}
}
// Sample getter method
public ApplicationContext getApplicationContext() {
return appContext;
}
I have added required spring jar and commons-logging in RCP plug-in dependencies.
Now, when I click on submit button from RCP screen and try to get bean defined in applicationContext (like shown below), I am getting above mentioned error.
Code:
public void myBusinessMethodWhichGetsCalledOnClickOfRCPButton() {
ApplicationContext appContext = Activator.getDefault().getApplicationContext();
Test t = appContext.getBean("test"); /* getting NoSuchBeanDefinitionException here */
.
.
.
.
.
.
}
Then why am I getting above exception?
Any help would be extremely helpful.
P.S.: When I run and try to get bean using simple public static void main() method, I am getting it w/o any error.
Thanks,
AkshayL.
[Updated on: Wed, 13 March 2013 10:13]
Report message to a moderator