Results 1 to 6 of 6

Thread: Do EJBs implemented with Spring need a EJB container

Hybrid View

  1. #1
    Join Date
    Jun 2011
    Posts
    10

    Default Do EJBs implemented with Spring need a EJB container

    Hi,
    I read over here in spring docs http://static.springsource.org/sprin...rence/ejb.html that you can implement EJBs. Does this require to be deployed on a application server /EJB container. Or does the spring container manage these EJBs. ?

    2) If a app server/ EJB container is required. Does it mean that 2 containers are started by the appserver (the EJB container and the Spring container.) Can beans in the spring application context call EJBs managed by the EJB container.

    thanks,
    Parag

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

    Default

    For EJBs (implemented with or without spring) you need an EJB container. So yes you need a full blown J2EE server...

    EJB Container != Spring Container (there is no such thing as a Spring Container, there is an applicationcontext which can be started by yourself, an ejb or war)...
    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
    Feb 2006
    Location
    Los Angeles, CA
    Posts
    79

    Default

    If you have to use EJB, then you can still use Spring to reference those beans and you can also delegate to Spring from an EJB. The real question is: do you need EJBs? there's nothing that you can do in an EJB that you can't do in Spring (transactions, remoting, business logic, etc.) (and usually with more flexibility!). Additionally, once you've started keeping your business logic in Spring, then you no longer need a full blow JavaEE/J2EE server. Heck, you don't even *need* a server! - just Java and maybe Tomcat, too ;-)
    Josh Long
    Spring Developer Advocate
    SpringSource, a division of VMware

    http://blog.SpringSource.org
    http://www.joshlong.com

  4. #4
    Join Date
    Jun 2011
    Posts
    10

    Default

    thanks for the reply, the reason I had asked this question was we were trying to find out if there was a way to integrate a big chunk of legacy EJB code in our spring based application without having to rewrite it. You say "you can still use Spring to reference those beans" . Can references to EJBs managed by a container other than spring's be injected into my Spring beans.

  5. #5
    Join Date
    Feb 2006
    Location
    Los Angeles, CA
    Posts
    79

    Default

    Yeah - of course. You can simply use the <jee:local-slsb id="myComponent" jndi-name="ejb/myBean" business-interface="com.mycom.MyComponent"/>, <jee:remote-slsb id="myComponent" jndi-name="ejb/myBean" business-interface="com.mycom.MyComponent"/> namespace elements and inject an EJB that way. Alternatively, if the bean is an EJB 3.0 bean, then you could also more than likely get it to work on Spring directly pretty easily, as Spring supports the transaction annotations and can be made to treat other annotations as stereotypes for Spring beans. If you're using JPA, then you can use @PersistenceContext in both Spring and EJB and the result is effectively the same, too. Also, @EJB-style injection can easily be find-and-replaced with @javax.inject.Inject or Spring's @Autowired. Let me know if this helps.
    Josh Long
    Spring Developer Advocate
    SpringSource, a division of VMware

    http://blog.SpringSource.org
    http://www.joshlong.com

  6. #6
    Join Date
    Jun 2011
    Posts
    1

    Default

    This is as close as i have found something to be related to my problem. I have pretty much the same question, only i've realized that i'm to use jee:local-slsb, but i can't access my bean via jndi! On the bad side, i'm using jaxws definition of service(i wrote a web service, my serviceImpl is a spring bean, but my business logic is EJB3.0, and i can't seem to get EJB's injected into serviceImpl. Even worse is that i'm not sure whether or not i am allowed to do that jee:local-slsb, and then pass that bean as a property to service bean...). I would much appreciate any sort of help regarding the issue...I am also using smart context, so maybe there could be the glitch...i have no idea...i'm as stuck as you can get...

Tags for this Thread

Posting Permissions

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