3 Replies Latest reply: Nov 13, 2011 4:44 AM by Oved Ourfali RSS

problem with bean injection

Oved Ourfali Newbie

Hey,

 

I have an ear, with a few jars and wars.

I try to deploy the restapi.war.

In its WEB-INF/applicationContext.xml I have:

 

  <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">

    <property name="environment">

      <props>

        <prop key="java.naming.factory.initial">

          org.jboss.as.naming.InitialContextFactory

        </prop>

        <prop key="java.naming.provider.url">

          jnp://localhost:${engine.jndi.port}

        </prop>

        <prop key="java.naming.factory.url.pkgs">

          org.jboss.naming:org.jnp.interfaces

        </prop>

      </props>

    </property>

  </bean>

 

and

 

  <bean name="backend" class="org.springframework.jndi.JndiObjectFactoryBean">

    <property name="jndiTemplate">

      <ref bean="jndiTemplate"/>

    </property>

    <property name="jndiName">

      <value>java:global/engine/engine-bll/Backend!org.ovirt.engine.core.common.interfaces.BackendLocal</value>

    </property>

  </bean>

 

When I try to deploy I get the following error is restapi.war:

10:47:58,529 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-3) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'backend' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: java:global/engine/engine-bll/Backend!org.ovirt.engine.core.common.interfaces.BackendLocal

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) [spring-2.5.6.jar:]

        at java.security.AccessController.doPrivileged(Native Method) [:1.6.0_24]

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423) [spring-2.5.6.jar:]

        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728) [spring-2.5.6.jar:]

        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380) [spring-2.5.6.jar:]

        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) [spring-2.5.6.jar:]

        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) [spring-2.5.6.jar:]

        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) [spring-2.5.6.jar:]

        at org.jboss.resteasy.plugins.spring.SpringContextLoaderListener.contextInitialized(SpringContextLoaderListener.java:44) [resteasy-spring-2.2.2.GA.jar:]

        at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]

        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)

        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)

        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_24]

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_24]

        at java.lang.Thread.run(Thread.java:662) [:1.6.0_24]

Caused by: javax.naming.NameNotFoundException: java:global/engine/engine-bll/Backend!org.ovirt.engine.core.common.interfaces.BackendLocal

        at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:90)

        at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:213)

        at javax.naming.InitialContext.lookup(InitialContext.java:392) [:1.6.0_24]

        at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155) [spring-2.5.6.jar:]

        at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:88) [spring-2.5.6.jar:]

        at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:153) [spring-2.5.6.jar:]

        at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178) [spring-2.5.6.jar:]

        at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95) [spring-2.5.6.jar:]

        at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105) [spring-2.5.6.jar:]

        at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:200) [spring-2.5.6.jar:]

        at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:186) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335) [spring-2.5.6.jar:]

        ... 24 more

 

10:47:58,534 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/api]] (MSC service thread 1-3) Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.spring.SpringContextLoaderListener: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'backend' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: java:global/engine/engine-bll/Backend!org.ovirt.engine.core.common.interfaces.BackendLocal

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) [spring-2.5.6.jar:]

        at java.security.AccessController.doPrivileged(Native Method) [:1.6.0_24]

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423) [spring-2.5.6.jar:]

        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728) [spring-2.5.6.jar:]

        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380) [spring-2.5.6.jar:]

        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) [spring-2.5.6.jar:]

        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) [spring-2.5.6.jar:]

        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) [spring-2.5.6.jar:]

        at org.jboss.resteasy.plugins.spring.SpringContextLoaderListener.contextInitialized(SpringContextLoaderListener.java:44) [resteasy-spring-2.2.2.GA.jar:]

        at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]

        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)

        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)

        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_24]

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_24]

        at java.lang.Thread.run(Thread.java:662) [:1.6.0_24]

Caused by: javax.naming.NameNotFoundException: java:global/engine/engine-bll/Backend!org.ovirt.engine.core.common.interfaces.BackendLocal

        at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:90)

        at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:213)

        at javax.naming.InitialContext.lookup(InitialContext.java:392) [:1.6.0_24]

        at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155) [spring-2.5.6.jar:]

        at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:88) [spring-2.5.6.jar:]

        at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:153) [spring-2.5.6.jar:]

        at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178) [spring-2.5.6.jar:]

        at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95) [spring-2.5.6.jar:]

        at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105) [spring-2.5.6.jar:]

        at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:200) [spring-2.5.6.jar:]

        at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:186) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369) [spring-2.5.6.jar:]

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335) [spring-2.5.6.jar:]

        ... 24 more

 

 

At start I thought it might be a deployment order issue, but I then added the

<initialize-in-order>true</initialize-in-order>

to my application.xml file.

 

Also, I see that the path above (java:global/engine/engine-bll/Backend!org.ovirt.engine.core.common.interfaces.BackendLocal) is the correct one (it is shown as one of the session beans in the engine-bll sub deployment).

 

What am I doing wrong?

 

Thank you,

Oved

  • 1. Re: problem with bean injection
    jaikiran pai Master

    Does adding:

     

    <property name="lookupOnStartup">

                <value>false</value>

            </property>

     

    to that org.springframework.jndi.JndiObjectFactoryBean work?

  • 2. Re: problem with bean injection
    Oved Ourfali Newbie

    Thank you for the quick response!

    It indeed helped (after adding the expectedType property as well).

    But then I ran into other issues (don't know if they are related yet).

     

    Trying to solve them now. Will update my status in this discussion.

     

    Oved

  • 3. Re: problem with bean injection
    Oved Ourfali Newbie

    Okay, it worked.

    Although, I get the following error, which is weird because the class it complains about is in a jar inside the WEB-INF/lib directory of the war.

    (it is in the jar restapi-jaxrs-3.0.0-0001.jar, which is in restapi/WEB-INF/lib).

    What's the reason for it?

     

    11:18:35,256 WARN  [org.jboss.modules] (MSC service thread 1-4) Failed to define class org/ovirt/engine/api/restapi/logging/Messages in Module "deployment.engine.ear.restapi.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/ovirt/engine/api/restapi/logging/Messages (Module "deployment.engine.ear.restapi.war:main" from Service Module Loader)

            at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:401) [jboss-modules.jar:1.0.2.GA]

            at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:261) [jboss-modules.jar:1.0.2.GA]

            at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:76) [jboss-modules.jar:1.0.2.GA]

            at org.jboss.modules.Module.loadModuleClass(Module.java:590) [jboss-modules.jar:1.0.2.GA]

            at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:183) [jboss-modules.jar:1.0.2.GA]

            at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:361) [jboss-modules.jar:1.0.2.GA]

            at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:310) [jboss-modules.jar:1.0.2.GA]

            at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:103) [jboss-modules.jar:1.0.2.GA]

            at java.util.ResourceBundle$Control.newBundle(ResourceBundle.java:2289) [:1.6.0_24]

            at java.util.ResourceBundle.loadBundle(ResourceBundle.java:1364) [:1.6.0_24]

            at java.util.ResourceBundle.findBundle(ResourceBundle.java:1328) [:1.6.0_24]

            at java.util.ResourceBundle.findBundle(ResourceBundle.java:1282) [:1.6.0_24]

            at java.util.ResourceBundle.findBundle(ResourceBundle.java:1282) [:1.6.0_24]

            at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1224) [:1.6.0_24]

            at java.util.ResourceBundle.getBundle(ResourceBundle.java:705) [:1.6.0_24]

            at org.ovirt.engine.api.restapi.logging.MessageBundle.populate(MessageBundle.java:19) [restapi-jaxrs-3.0.0-0001.jar:]

            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_24]

            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_24]

            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_24]

            at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_24]

            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1414) [spring-2.5.6.jar:]

            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1375) [spring-2.5.6.jar:]

            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335) [spring-2.5.6.jar:]

            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) [spring-2.5.6.jar:]

            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) [spring-2.5.6.jar:]

            at java.security.AccessController.doPrivileged(Native Method) [:1.6.0_24]

            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) [spring-2.5.6.jar:]

            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) [spring-2.5.6.jar:]

            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-2.5.6.jar:]

            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) [spring-2.5.6.jar:]

            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) [spring-2.5.6.jar:]

            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) [spring-2.5.6.jar:]

            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429) [spring-2.5.6.jar:]

            at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728) [spring-2.5.6.jar:]

            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380) [spring-2.5.6.jar:]

            at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) [spring-2.5.6.jar:]

            at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) [spring-2.5.6.jar:]

            at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) [spring-2.5.6.jar:]

            at org.jboss.resteasy.plugins.spring.SpringContextLoaderListener.contextInitialized(SpringContextLoaderListener.java:44) [resteasy-spring-2.2.2.GA.jar:]

            at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

            at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

            at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]

            at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)

            at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)

            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_24]

            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_24]

            at java.lang.Thread.run(Thread.java:662) [:1.6.0_24]

    Caused by: java.lang.NoClassDefFoundError: IllegalName: org/ovirt/engine/api/restapi/logging/Messages

            at java.lang.ClassLoader.preDefineClass(ClassLoader.java:477) [:1.6.0_24]

            at java.lang.ClassLoader.defineClassCond(ClassLoader.java:626) [:1.6.0_24]

            at java.lang.ClassLoader.defineClass(ClassLoader.java:616) [:1.6.0_24]

            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) [:1.6.0_24]

            at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:397) [jboss-modules.jar:1.0.2.GA]

            ... 46 more