Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to inject EJB beans with Spring DI.

 
sam White
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

With Spring 3, EJB3,I created a project EAR which consist of a EJB web service consumer layer and a WAR layer.
The WAR layer have to access some APIs that are written in the EJB layer.

During the deployment process, JBOSS AS7 throws the following exception:

01:10:27,519 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) Starting deployment of "CategoryClient-ear.ear"
01:10:27,724 INFO [org.jboss.as.server.deployment] (MSC service thread 1-5) Starting deployment of "CategoryClient-web.war"
01:10:27,725 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) Starting deployment of "CategoryClient-ejb-1.0-SNAPSHOT.jar"
01:10:28,145 INFO [org.jboss.as.jpa] (MSC service thread 1-4) added javax.persistence.api dependency to CategoryClient-ear.ear
01:10:28,146 INFO [org.jboss.as.jpa] (MSC service thread 1-1) added javax.persistence.api dependency to CategoryClient-ejb-1.0-SNAPSHOT.jar
01:10:28,146 INFO [org.jboss.as.jpa] (MSC service thread 1-3) added javax.persistence.api dependency to CategoryClient-web.war
01:10:28,162 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-7) JNDI bindings for session bean named CategoryManagerImpl in deployment unit subdeployment "CategoryClient-ejb-1.0-SNAPSHOT.jar" of deployment "CategoryClient-ear.ear" are as follows:

java:global/CategoryClient-ear/CategoryClient-ejb-1.0-SNAPSHOT/CategoryManagerImpl!ix.houseware.category.CategoryManager
java:app/CategoryClient-ejb-1.0-SNAPSHOT/CategoryManagerImpl!ix.houseware.category.CategoryManager
java:module/CategoryManagerImpl!ix.houseware.category.CategoryManager
java:global/CategoryClient-ear/CategoryClient-ejb-1.0-SNAPSHOT/CategoryManagerImpl
java:app/CategoryClient-ejb-1.0-SNAPSHOT/CategoryManagerImpl
java:module/CategoryManagerImpl

01:10:28,426 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/CategoryClient-web]] (MSC service thread 1-7) Initializing Spring root WebApplicationContext
01:10:28,727 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/CategoryClient-web]] (MSC service thread 1-7) Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'categoryFinderController' defined in "/content/CategoryClient-ear.ear/CategoryClient-web.war/WEB-INF/classes/ix/houseware/category/controller/CategoryFinderController.class": Unsatisfied dependency expressed through constructor argument with index 0 of type [ix.houseware.category.CategoryManager]: : No matching bean of type [ix.houseware.category.CategoryManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [ix.houseware.category.CategoryManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:730) [spring-beans-3.0.6.RELEASE.jar:]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196) [spring-beans-3.0.6.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1003) [spring-beans-3.0.6.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:907) [spring-beans-3.0.6.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) [spring-beans-3.0.6.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [spring-beans-3.0.6.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) [spring-beans-3.0.6.RELEASE.jar:]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-beans-3.0.6.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) [spring-beans-3.0.6.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) [spring-beans-3.0.6.RELEASE.jar:]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) [spring-beans-3.0.6.RELEASE.jar:]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) [spring-context-3.0.6.RELEASE.jar:]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) [spring-context-3.0.6.RELEASE.jar:]
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282) [spring-web-3.0.6.RELEASE.jar:]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204) [spring-web-3.0.6.RELEASE.jar:]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) [spring-web-3.0.6.RELEASE.jar:]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.1.Final.jar:7.1.0.Alpha1-SNAPSHOT]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) [jbossweb-7.0.1.Final.jar:7.1.0.Alpha1-SNAPSHOT]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.1.0.Alpha1-SNAPSHOT.jar:7.1.0.Alpha1-SNAPSHOT]
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:885) [:1.6.0_03-p4]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907) [:1.6.0_03-p4]
at java.lang.Thread.run(Thread.java:619) [:1.6.0_03-p4]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [ix.houseware.category.CategoryManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:924) [spring-beans-3.0.6.RELEASE.jar:]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:793) [spring-beans-3.0.6.RELEASE.jar:]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707) [spring-beans-3.0.6.RELEASE.jar:]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795) [spring-beans-3.0.6.RELEASE.jar:]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723) [spring-beans-3.0.6.RELEASE.jar:]
... 23 more

01:10:28,731 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-7) Error listenerStart
01:10:28,731 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-7) Context [/CategoryClient-web] startup failed due to previous errors
01:10:28,741 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/CategoryClient-web]] (MSC service thread 1-7) Closing Spring root WebApplicationContext
01:10:28,743 INFO [org.jboss.web] (MSC service thread 1-7) registering web context: /CategoryClient-web
01:10:28,755 INFO [org.jboss.as.server.controller] (DeploymentScanner-threads - 1) Deployed "CategoryClient-ear.ear"


The CategoryManagerImpl.java is in EJB layer:



The CategoryFinderController.java is in the WAR module:



Here is my WEB-INF/mvc-dispatcher-servlet.xml in WAR file is shown below:



I may be have mis-used Spring DI with EJB in the WAR module, but I could not found what is wrong with the configuration.

Any suggestion is very appreciated.

Sam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic