views:

299

answers:

7

On the Tomcat FAQ it says: "Tomcat is not an EJB server. Tomcat is not a full J2EE server."

But if I:

  • use Spring to supply an application context
  • annotate my entities with JPA annotations (and use Hibernate as a JPA provider)
  • configure C3P0 as a connection pooling data source
  • annotate my service methods with @Transactional (and use Atomikos as JTA provider)
  • Use JAXB for marshalling and unmarshalling
  • and possibly add my own JNDI capability

then don't I effectively have a JEE application server? And then aren't my beans EJBs? Or is there some other defining characteristic?

What is it that a JEE compliant app server gives you that you can't easily/readily get from Tomcat with some 3rd party subsystems?

+1  A: 

An EJB implementation would be a bean written and packaged to run on any compliant EJB server. If you do what you describe, it may work, but it won't be portable to another vendor's application server.

So EJB is a standard that adheres to a specific specification and is therefore portable.

In practice many EJB's are not fully compliant or application server neutral. However, in the main they are, so the small incompatibilities would be much easier to fix if you changed application server vendors than attempting to move the architecture you described to a GlassFish, JBoss or Weblogic server.

EDIT: In response to your comment you would not have an EJB appropriately annotated and/or configured via XML in such a way that code that accessed it in EJB compliant ways would be able to use it without changes.

There are two angles to your comment. One is what functionality would you lose deploying on a JBoss or any of the others instead of Tomcat? Likely nothing, if you brought along all of the frameworks you relied on. However, if you wanted to move your code to Weblogic, for example, to use some of its features, then your code would need some likely significant changes to keep up.

I am not saying that you cannot replicate all EJB functionality (certainly the subset you care about) via other means, just that it is not the spec, and therefore not implementation independent.

Yishai
Why would the architecture I describe not be portable to a real EJB application server? Would it not run? Would it need to be reconfigured or rewritten?
HDave
+5  A: 

EJBs are JavaEE components that conform to the javax.ejb API.

JavaEE is a collection of APIs, you don't need to use all of them.

Tomcat is a "partial" JavaEE server, in that it only implements some of the JavaEE APIs, such as Servlets and JNDI. It doesn't implement e.g. EJB and JMS, so it's not a full JavaEE implementation.

If you added some additional bits and pieces (e.g. OpenEJB, HornetQ), you'd add the missing parts, and you'd end up with a full JavaEE server. But out of the box, Tomcat isn't that, and doesn't try to be.

skaffman
So essentially, my annotated POJOs have much of the functionality of an EJB (all the functionality I care about), but because Tomcat doesn't implement javax.ejb (and my beans don't use those APIs) they aren't officially EJBs.Am I correct in assuming that my architecture will run within an app server just fine?
HDave
@HDave: There's more to EJB than the JPA annotations. They cover things like transactions, security and lifecycle, which *complement* and *extend* the JPA annotations.
skaffman
Sure -- by annotations I meant JPA + Transaction + Security. I assume these will all work in a JEE app server. Is this right?
HDave
+3  A: 

1) You're confusing JPA entities with EJBs. While JPA belongs to the EJB3 specification, it was always meant to be a standalone technology.

2) EJBs are: stateless beans, stateful beans and message driven beans. While each of these functionalities can easily be achieved using spring, spring just does not use this terminology. In Spring, you don't have POJO + "magic" as in EJBs, in Spring it's POJO + your own configuration (which sometimes feels like magic, too). The main difference is that spring does more and the application server does less, which is why a spring app is happy with a tomcat while an ejb3 app needs a 'real' application server.

In my opinion, 90% of applications can be deployed using spring + tomcat, ejb3 is rarely needed.

seanizer
+1  A: 

then don't I effectively have a JEE application server? And then aren't my beans EJB's? Or is there some other defining characteristic?

Quick answer EJBs actually have to follow a JEE specification. Tomcat is a JEE container not an app server.

What is it that a JEE compliant app server gives you that you can't easily/readily get from Tomcat with some 3rd party subsystems?

Quick answer to your second question. In your case most likely nothing.

EJBs tend to be really heavy objects and people ended up using them to solve problems when they were essentially overkill. Frameworks like Spring were created to solve those problems without using EJBs. I think the first book where Spring was introduced was even called "J2EE development without EJB."

BrennaSoft
First, Tomcat is **NOT** a Java EE container. Second, EJBs = heavy was true for J2EE 1.4 but does **NOT** apply to EJB3. We are not in 2004 anymore...
Pascal Thivent
It would make sense to me that if your container does not support EJB, then it is not a Java EE container. According to Wikipedia however, Tomcat is an application server (which I believe is technically true, though confusing):http://en.wikipedia.org/wiki/Application_server
HDave
A: 

Outside of the strict definition of what is and isn't an EJB, you're adding a lot of stuff to Tomcat. Even if what you have is an EJB server, it's not really plain Tomcat anymore.

The FAQ is correct: Tomcat is not an EJB server. However, it can be that or many other things if you pile on enough extra libraries and code.

Greg Harman
+2  A: 

Indeed, if you put enough effort you can almost turn Tomcat/Spring into a full-fledged heavyweight application server :) You could even embed a portable EJB3 container...

What is it that a JEE compliant app server gives you that you can't easily/readily get from Tomcat with some 3rd party subsystems?

There are still a few features that are hard to get with 3rd party modules:

  • stateful session beans (SFSB)
  • extended persistence context
  • application client container / java web start
  • clustering depending on the app. server
  • CORBA interoperability
  • JCA integration ~
  • remoting ~
  • container-managed transactions ~
  • decent management of distributed transactions (e.g. recover heuristic tx)

Entries with ~ are also supported by Spring, but not so trivially, at least to my best knowledge.

A few more details in this answer: EJB vs Spring

ewernli
+1 Good answer. But I would also add failover and recovery, you won't get that with a Tomcat on steroids and that's an important part of a full-fledged middleware specification and implementation.
Pascal Thivent
That's right. I considered that part of clustering, even if it's not exactly the same. Also, the JEE specs are written so that clustering can be supported, but they don't mandate it to be compliant. But I fully agree that this is an important aspect in the choice of an app. server.
ewernli
+2  A: 

But if I add (...) then don't I effectively have a JEE application server? And then aren't my beans EJBs? Or is there some other defining characteristic?

No, you don't have a Java EE application server, a full-fledged Java EE application server is more than Tomcat + Spring + a standalone Transaction Manager. And even if you add a JMS provider and an EJB container, you still won't have a Java EE server. The glue between all parts is IMO important and is part of the added value of a Java EE container.

Regarding EJBs, the EJB specification is much more than JPA and specifices also Session Beans and Message Driven Beans (actually, I don't really consider JPA Entities as EJBs even if JPA is part of the EJB 3.0 specification in Java EE 5 for historical reasons - which is not true anymore in Java EE 6, JPA 2.0 and EJB 3.1 are separate specifications). I should also mention that a Spring bean annotated with @Transactional is not equivalent to a Session Bean. A Java EE container can do more things with Session Beans (see below). You may not need them though but still, they are not strictly equivalent.

Last thing, Java EE containers implement a standard, the Spring container does not, it is proprietary.

What is it that a JEE compliant app server gives you that you can't easily/readily get from Tomcat with some 3rd party subsystems?

As I said, I think that the "glue" is a part of the added value and highly contributes to the robustness of the whole. Then, ewernli's answer underlined very well what is difficult to achieve. I'd just add:

  • Clustering and Fail-over (to achieve fault-tolerance)
  • Administration facilities

Yes, a good Java EE server will do pretty neat things to improve fault tolerance (clustering of connection pools, JNDI tree, JMS destinations, automatic retry with idempotent beans, smart EJB clients, transaction recovery, migration of services, etc). For "mission critical" applications - the vast majority are not - this is important. And in such cases, libraries on top of the Servlet API are IMO not a replacement.

Pascal Thivent