Do you have a short example to share (kinda Hello Worldline)?
I already made that working few month ago so it should a matter of
configuration.

Jean-Louis

2012/8/31 laredotornado <laredotorn...@gmail.com>

> Hi,
>
> I'm using OpenEJB 4.0.0, Spring 3.1.0.RELEASE, and JUnit 4.8.1.  I'm trying
> to test a Spring controller that attempts to get an EJB from JNDI …
>
>                 final Context context = new InitialContext();
>                 Object myprojectStandardMgrHomeObj = context.lookup(
> "MyProjectStandardManager" );
>                 final Object remoteObj =
> PortableRemoteObject.narrow(myprojectStandardMgrHomeObj,
> MyProjectStandardManagerHome.class );
>                 final MyProjectStandardManagerHome myprojectStdMgrHome =
> (MyProjectStandardManagerHome)
> PortableRemoteObject.narrow(myprojectStandardMgrHomeObj,
> MyProjectStandardManagerHome.class );
>
> but I'm confused about InitialContexts.  In JUnit, I've added the JAR files
> that contain my ejb-jar.xml's to OpenEJB …
>
>         @BeforeClass
>         public static void setupBeforeClass() throws NamingException,
> CreateException, IOException {
>                 final Properties p = new Properties();
>                 p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
>                 p.setProperty("openejb.deployments.classpath.include",
> ".*\\.jar");
>                 final InitialContext initialContext = new
> InitialContext(p);
>                 Enumeration<URL> ejbJars =
>
> AbstractCorrelationsTest.class.getClassLoader().getResources("META-INF/ejb-jar.xml");
>                 while (ejbJars.hasMoreElements()) {
>                         URL url = ejbJars.nextElement();
>                         System.out.println("app = " + url);
>                 }       // while
>         } // setupBeforeClass
>
> but Spring doesn't seem to see them when it tries to initialize its
> context.
> It dies with the exception, "Error creating bean with name
> 'standardManager'
> defined in URL [jar:file:/path/to/xml/file.xml]: Invocation of init method
> failed; nested exception is javax.naming.NoInitialContextException: Need to
> specify class name in environment or system property, or as an applet
> parameter, or in an application resource file:
> java.naming.factory.initial".  How do I make OpenEJB create the EJBs in the
> same context as which Spring is looking?
>
> Thanks, - Dave
>
>
> ps - The complete exception I'm seeing is …
>
> ERROR [main] (TestContextManager.java:324) - Caught exception while
> allowing
> TestExecutionListener
>
> [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1901b54e
> ]
> to prepare test instance
> [org.mainco.correlations.controller.StandardsUploadControllerTest@3f2620b5
> ]
> java.lang.IllegalStateException: Failed to load ApplicationContext
>         at
>
> org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
>         at
>
> org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
>         at
>
> org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
>         at
>
> org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
>         at
>
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
>         at
>
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
>         at
>
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>         at
>
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)
>         at
>
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
>         at
>
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
>         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>         at
> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>         at
>
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>         at
>
> org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
>         at
>
> org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
>         at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>         at
>
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
>         at
>
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
>         at
>
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: org.springframework.beans.factory.BeanCreationException: Error
> creating bean with name 'skillUrlMappings' defined in class path resource
> [myprojectx/skills/controller/MyProjectSkillControllers.cfg.xml]:
> Initialization of bean failed; nested exception is
> org.springframework.beans.factory.BeanCreationException: Error creating
> bean
> with name 'myprojectGetAvailableStandardSetsForProductController' defined
> in
> class path resource
> [myprojectx/skills/controller/MyProjectSkillControllers.cfg.xml]: Cannot
> resolve reference to bean 'standardManager' while setting bean property
> 'standardManager'; nested exception is
> org.springframework.beans.factory.BeanCreationException: Error creating
> bean
> with name 'standardManager' defined in URL
>
> [jar:file:/Users/davea/.m2/repository/myproject/jars/myproject-skills-impl/4.2-SNAPSHOT/myproject-skills-impl-4.2-SNAPSHOT.jar!/_module_config/managers/proxies.remote.COMMON.xml]:
> Invocation of init method failed; nested exception is
> javax.naming.NoInitialContextException: Need to specify class name in
> environment or system property, or as an applet parameter, or in an
> application resource file:  java.naming.factory.initial
>         at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
>         at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
>         at
>
> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
>         at
>
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
>         at
>
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
>         at
>
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
>         at
>
> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
>         at
>
> org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
>         at
>
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
>         at
>
> org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)
>         at
>
> org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
>         at
>
> org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
>         at
>
> org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
>         at
>
> org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
>         ... 25 more
> Caused by: org.springframework.beans.factory.BeanCreationException: Error
> creating bean with name
> 'myprojectGetAvailableStandardSetsForProductController' defined in class
> path resource
> [myprojectx/skills/controller/MyProjectSkillControllers.cfg.xml]: Cannot
> resolve reference to bean 'standardManager' while setting bean property
> 'standardManager'; nested exception is
> org.springframework.beans.factory.BeanCreationException: Error creating
> bean
> with name 'standardManager' defined in URL
>
> [jar:file:/Users/davea/.m2/repository/myproject/jars/myproject-skills-impl/4.2-SNAPSHOT/myproject-skills-impl-4.2-SNAPSHOT.jar!/_module_config/managers/proxies.remote.COMMON.xml]:
> Invocation of init method failed; nested exception is
> javax.naming.NoInitialContextException: Need to specify class name in
> environment or system property, or as an applet parameter, or in an
> application resource file:  java.naming.factory.initial
>         at
>
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
>         at
>
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
>         at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
>         at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
>         at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
>         at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
>         at
>
> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
>         at
>
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
>         at
>
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
>         at
>
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
>         at
>
> org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1093)
>         at
>
> org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:286)
>         at
>
> org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.registerHandlers(SimpleUrlHandlerMapping.java:129)
>         at
>
> org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.initApplicationContext(SimpleUrlHandlerMapping.java:104)
>         at
>
> org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119)
>         at
>
> org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:72)
>         at
>
> org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
>         at
>
> org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117)
>         at
>
> org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:92)
>         at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
>         at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1448)
>         at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
>         ... 38 more
> Caused by: org.springframework.beans.factory.BeanCreationException: Error
> creating bean with name 'standardManager' defined in URL
>
> [jar:file:/Users/davea/.m2/repository/myproject/jars/myproject-skills-impl/4.2-SNAPSHOT/myproject-skills-impl-4.2-SNAPSHOT.jar!/_module_config/managers/proxies.remote.COMMON.xml]:
> Invocation of init method failed; nested exception is
> javax.naming.NoInitialContextException: Need to specify class name in
> environment or system property, or as an applet parameter, or in an
> application resource file:  java.naming.factory.initial
>         at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
>         at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
>         at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
>         at
>
> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
>         at
>
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
>         at
>
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
>         at
>
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
>         at
>
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
>         ... 59 more
> Caused by: javax.naming.NoInitialContextException: Need to specify class
> name in environment or system property, or as an applet parameter, or in an
> application resource file:  java.naming.factory.initial
>         at
> javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
>         at
> javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
>         at
> javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
>         at javax.naming.InitialContext.lookup(InitialContext.java:392)
>         at
> org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
>         at
> org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
>         at
> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
>         at
> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
>         at
>
> org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
>         at
>
> org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
>         at
>
> org.springframework.ejb.access.AbstractRemoteSlsbInvokerInterceptor.lookup(AbstractRemoteSlsbInvokerInterceptor.java:100)
>         at
>
> org.springframework.ejb.access.AbstractSlsbInvokerInterceptor.refreshHome(AbstractSlsbInvokerInterceptor.java:122)
>         at
>
> org.springframework.ejb.access.SimpleRemoteSlsbInvokerInterceptor.refreshHome(SimpleRemoteSlsbInvokerInterceptor.java:163)
>         at
>
> org.springframework.ejb.access.AbstractSlsbInvokerInterceptor.afterPropertiesSet(AbstractSlsbInvokerInterceptor.java:109)
>         at
>
> org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean.afterPropertiesSet(SimpleRemoteStatelessSessionProxyFactoryBean.java:100)
>         at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
>         at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
>         ... 66 more
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Confusion-about-InitialContexts-with-my-Spring-JUnit-test-tp4657188.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Reply via email to