Results 1 to 7 of 7

Thread: spring 3 accessing EJB3

  1. #1
    Join Date
    Sep 2011
    Posts
    18

    Default spring 3 accessing EJB3

    Hi all!

    Please can you tell me what's wrong or what Im am missing in order to access EJB within Spring?
    here's my applicaation context file:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:jee="http://www.springframework.org/schema/jee"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/jee
    		http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
    		                       
    <!-- 
    	<context:component-scan base-package="sk.skhplus.retail.controller" />
     
     
     <jee:local-slsb id="material"
    jndi-name="skh-retail/MaterialDaoBean"
    business-interface="sk.skhplus.core.material.ejb.intf.MaterialDaoLocal"/>
     -->
     
     
     <bean id="hello" class="sk.skhplus.retail.controller.HelloWorldController"></bean>
     
     <bean id="data" class="sk.skhplus.retail.controller.DataSourceController"></bean>
    
    	<bean id="viewResolver"
    		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    		<property name="prefix" value="/jsp/" />
    		<property name="suffix" value=".jsp" />
    	</bean>
    
    		
    		<bean id="materialBean"
    		class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">
    		<property name="jndiName" value="skh-retail/MaterialDaoBean" />
    		<property name="businessInterface" value="sk.skhplus.core.material.ejb.intf.MaterialDaoLocal"/>
    		<property name="resourceRef" value="true" />
    		</bean>
    		 
    		
    		<bean id="dataSource"
    		class="sk.skhplus.retail.controller.DataSourceController">
    		<property name="materialDaoBean" ref="materialBean" />
    		</bean>
    		 
    		 
    
       </beans>

    and here is what jBoss is saying:

    Code:
    11:20:13,152 INFO  [DefaultListableBeanFactory] Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@7796af5d: defining beans [hello,data,viewResolver,materialBean,dataSource]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@5f890954
    11:20:13,152 ERROR [DispatcherServlet] Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/springmvc-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy280 implementing sk.skhplus.core.material.ejb.intf.MaterialDaoLocal,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'sk.skhplus.core.material.ejb.MaterialDaoBean' for property 'materialDaoBean'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy280 implementing sk.skhplus.core.material.ejb.intf.MaterialDaoLocal,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [sk.skhplus.core.material.ejb.MaterialDaoBean] for property 'materialDaoBean': no matching editors or conversion strategy found
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    I know this is perhaps trivial, but Im newbie in spring and I need this for my project. As I have read articles about accessing EJBs that declarations should be enought.
    excuse my english, its not my primary language .

    Thanks for help!

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    I suggest the search as it seems you are making the classic error of trying to convert a proxy to a concrete implementation. You should program to interfaces and not concrete implementations, also since you are using EJB3 you should have enough on a simple JNDI lookup so there should be no need for a full jee lookup.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2011
    Posts
    18

    Default

    How do you know form that scratch of code that Im doing implementation programming?

    citing from Spring In Action 2nd edition:

    Declaring EJB 3 session beans in Spring
    As I mentioned earlier, EJB 3 simplifies the session bean lookup process by elimi-
    nating the notion of a home interface. Instead of looking up a session bean
    through a home interface that was retrieved through JNDI, EJB 3 session beans are
    retrieved directly from JNDI.
    .
    .
    .

    Fortunately, Spring provides the ability to wire JNDI-stored objects just like any
    other bean in the application context. The trick involves using Spring’s JndiOb-
    jectFactoryBean. The following snippet of XML from the Spring application
    context shows how you might declare an EJB 3 traffic service session bean:
    <bean id="trafficService"
    class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName" value="ejb/TrafficService" />
    <property name="resourceRef" value="true" />
    </bean>
    As a factory bean, JndiObjectFactoryBean produces a proxy to the real session
    bean (see figure 11.2), which it looks up from a JNDI repository using the jndi-
    Name property. The resourceRef property indicates that the EJB should be looked
    up as a Java resource, in effect prefixing the value of jndiName with java:comp/
    env/ before performing the lookup.


    ..perhaps I didn't got it right, so can you please tell me where Im doing mistake?

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default


    How do you know form that scratch of code that Im doing implementation programming?
    By looking at your stack trace.

    Code:
    Cannot convert value of type [$Proxy280 implementing sk.skhplus.core.material.ejb.intf.MaterialDaoLocal,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [sk.skhplus.core.material.ejb.MaterialDaoBean] for property 'materialDaoBean': no matching editors or conversion strategy found
    You create a proxy which implements MaterialDaoLocal (well the lookup does that) and you expect to convert it to a concrete implementation (MaterialDaoBean) because it is a dynamic proxy that isn't obviously isn't going to work. You should program to the interface (MaterialDaoLocal)...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Sep 2011
    Posts
    18

    Default

    okay, its resolved by reffering to bean INTERFACE in bean deffinition like:

    Code:
    <bean id="materialBean"
    		class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">
    		<property name="jndiName" value="skh-retail/MaterialDaoBean/Local" />
    		<property name="businessInterface" value="sk.skhplus.core.material.ejb.intf.MaterialDaoLocal"/>
    		<property name="resourceRef" value="true" />
    		</bean>
    Thanks for interest and help!

  6. #6
    Join Date
    Nov 2011
    Posts
    3

    Default

    Wanted to invoke service object from Spring webflow Action class, since the service objects on EJB container, not sure how to autowire the service in Web layer

  7. #7
    Join Date
    Sep 2011
    Posts
    11

    Default

    Hello greenGold,

    I was trying to develop the same application but was unsuccessful.Can u please help me out in this as i am new to both spring and Ejb. I was constantly getting the error ejb not bound.
    Problem was my bean was not able to bind. Can you please tell me a small tutorial how to bind EJB and spring and hibernate.
    And your EJB was in different project altogether or in the same one
    Please help me out in this

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •