What is EJB alternative in Spring Framework

前端 未结 3 1162
孤独总比滥情好
孤独总比滥情好 2021-02-10 02:53

I am trying to learn Spring Framework, before that I used to create application with EJBs

[Web services]->[Business Layer]->[DAO Layer] | [Database]

相关标签:
3条回答
  • 2021-02-10 03:35

    Jersey (RestAPi) alternative in Spring?

    Spring MVC does this perfectly fine, in my opinion. Just annotate your methods in your controller as the REST apis you want to use.

    EJB alternative in Spring (as EJB supports remoting, each lookup call to a method is treated as a transaction, calls to EJB's method could be intercepted and it comes with state-full and stateless flavors)?

    There is no full alternative. There are several techniques that implement this in parts: Spring remoting for remote calls, Spring transactions as transactions, Spring AOP interceptors for intercepting calls. However, for example XA transactions on remote calls are something you don't get as such in Spring. Spring however works fine with EJBs, so if you prefer them, you can still have them and use Spring in other parts of your software.

    Timer Service alternative in Spring?

    Spring task scheduling

    Message Drive Bean alternative in Spring?

    Message Listener Containers

    Interceptor alternative is AOP in Spring (As per my experience and that serve my purpose)

    There are several levels of interceptors in spring. There are handler interceptors in mvc, there are bean call interceptors like the SpringAutowiringInterceptor, and there are AOP-based interceptors that can be used in multiple layers.

    JPA(entity manager) alternative in spring?

    Spring has multiple of these as well. It's actually quite straightforward to just use JPA with Spring-Data, it's designed to integrate to JPA. There are Spring JDBC and other data layer alternatives though if Spring Data is not what you want.

    0 讨论(0)
  • 2021-02-10 03:51
    • Jersey (RestAPi) alternative in Spring ⇨ it's rest api (in spring with @Path annotation) or spring mvc if you want to use controllers (@Controller annotation)!
    • EJB alternative in Spring ⇨ Spring doesn't give statefull bean out of a box but you can use @Service annotation (or @Repository for DAO) but you have to handle transactions manually (with annotations for example)
    • Message Drive Bean alternative ⇨ There is no equivalent out of the box in Spring, you could use injection and librairies of Spring to get it working (package org.springframework.jms should contains what you need)!
    • JPA(entity manager) alternative is not ejb ⇨ so it can be used in Spring.

    Spring is a lighweight library so you can do all you do with EJB but it's more configurable so you will have more work to do the same that EJB do. But this configuration brings you some advantages: you have the hand on it!

    0 讨论(0)
  • 2021-02-10 03:52

    This explains Spring and Java EE (which is what you would have used EJBs in) side by side: http://www.slideshare.net/reza_rahman/java-ee-and-spring-sidebyside-34320697

    1. Jersey offers Spring solutions too - see their website
    2. Spring does support remote calls through, e.g., RMI; It also supports transactions; AFAIK, no explicit stateful/stateless Spring Components - it depends on how you use it
    3. AFAIK nothing as awesome as TimerService, however, you could use Quartz
    4. Spring offers MDPs (Message-Driven POJOs)
    5. Spring does support JPA - see first link.

    Another cool comparison slideshare: http://www.slideshare.net/kelapure/java-e-evsspringshootout

    0 讨论(0)
提交回复
热议问题