Announcement Announcement Module
No announcement yet.
Introduction of Spring broke @EJB usage Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Introduction of Spring broke @EJB usage


    I have a project that consists of EJB3, JSF and now Spring. I use to access the EJBs from the JSF beans using the @EJB annotation for injection. Since I introduced Spring into the mix to manage the JSF beans I get the following exception:

    org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [MyEJBInterface] is defined: Unsatisfied 
    dependency of type [MyEJBInterface]: expected at least 1 matching bean
    	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(
    	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(
    	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$EjbRefElement.getResourceToInject(
    	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(
    	at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(
    	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessAfterInstantiation(
    	... 116 more
    Am I supposed to configure something to allow the normal use of @EJB or will Spring be a bit invasive and not allow normal use in this case?

    Thanks in advance.

  • #2
    I am not sure if it is spring fault.
    cause I am not sure if Spring process @EJB annotation.

    Asaik @Resource in ejb3 technology is used to retrieve resources from jndi but spring in its default (you can customize this behaviour) inject spring managed beans instead of jndi.

    This exception you got is because you just want Spring to autowire beans
    (perhaps by using @Autowired) and you have more than one bean in your context of type "MyEjbInterface".

    Take a look in your context file and pls take a look at beans of type ProxyFactoryBeans, because these are also of type MyEjbInterface.

     <bean id="readerTarger" class="pl.test.service.impl.Reader"/>
       <bean id="reader" class="org.springframework.aop.framework.ProxyFactoryBean">
       		<property name="interceptorNames">
       		<property name="target">
       			<ref bean="readerTarger"/>
    If Reader class implements IReadable you will get get 2 bean of type IReadable in your context.
    In this case you would should :
    define your "real" bean as inner bean - define readerTarger as inner bean,
    use @Qualifier


    • #3
      Thanks for the info.

      I had a look at the Spring code and it does try to inject fields that are annotated with @EJB.
      Normally it is possible to use the @EJB annotation in your web container and the application server will use JNDI to locate the correct EJB/Proxy.

      So if I get Spring to leave the @EJB alone will the application container still do that for me or will I have to go via Spring and tell spring to use JNDI for @EJB?

      The @Resource is used for injection of resources like SessionContext, EntityManager etc. where @EJB is session beans

      My context file contains very limited config as I opted for annotations. I have no ProxyFactoryBeans defined in the file.

      The fact the Spring does handle @EJB I am certain of, the rest might be incorrectly interpreted by me