POJO与EJB对EJB 3 [英] POJO vs EJB vs EJB 3

查看:115
本文介绍了POJO与EJB对EJB 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有任何Java Class可能看起来像POJO,EJB和EJB 3的例子?我正在努力了解这些java技术,但是遇到麻烦。我希望如果我能看到所有这三个的执行情况看起来都会有所帮助。

解决方案

POJO 代表Plain-Old-Java-Object - 只是一个普通的Java类,而不是需要以特定方式改变类以使其与框架一起工作的旧技术。

  class MyService {

public String sayHello(){returnhello world; }

}

因为这样的POJO可以在任何地方使用普通类使用。但是,如果要从中构建企业应用程序,您仍然需要一些框架 - Spring 是一个很好的例子可以直接与POJO一起工作的框架。



EJB2 不再相关,因此您可以忽略它 - 除非您需要维护一些遗产码。为了满足您的好奇心,与上述相同的示例将需要几个类和xml描述符来运行 - 很容易看出为什么它变得过时。



EJB3 是用于开发替代EJB2的企业应用程序的最新标准,并且基于采用POJO和注释的概念,以便可以在企业应用程序中使用。

  @Stateless 
class MyService {
public String sayHello(){returnhello world; }
}

正如你所看到的,它与POJO非常相似。实际上,为EJB3编写的大多数应用程序都可以很容易地转换成与Spring一起工作,通常情况下也可以使用。


Does anyone have any example of what a Java Class might look like as a POJO, EJB, and EJB 3? I'm trying to understand these java technologies but am having trouble. I was hoping it would help if I could see what an implementation of all three would look like.

解决方案

POJO stands for Plain-Old-Java-Object - just a normal Java class as opposed to older technologies that required changing the class in specific ways to make it work with their framework.

class MyService {

    public String sayHello() { return "hello world"; }

}

As such POJOs can be used anywhere a normal class can be used. However if you want to build an enterprise application out of them you still need some framework - Spring is a good example of a framework that can work directly with POJOs.

EJB2 is no longer relevant so you can ignore it - unless you need to maintain some legacy code. To satisfy your curiosity the same example as above would require several classes and xml descriptors to make it run - it's easy to see why it became obsolete.

EJB3 is the latest standard for developing enterprise applications which replaces EJB2 and is based on concept of taking POJOs and annotating them so that they can be used in enterprise app.

@Stateless
class MyService {
    public String sayHello() { return "hello world"; }
}

As you can see it's very similar to POJOs. In fact most application written for EJB3 can easily be converted to work with Spring, and usually the other way works too.

这篇关于POJO与EJB对EJB 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆