EJB企业应用程序不需要EJB接口 [英] EJB enterprise application doesn't need EJB interface

查看:77
本文介绍了EJB企业应用程序不需要EJB接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Java EE应用程序并将无状态会话bean添加到EJB项目中.EJB项目是web/WAR项目中的依赖项,我将在EJB项目中创建的EJB注入到我的一个servlet中.这工作正常,我能够在Web应用程序项目的servlet中部署和调用此EJB的方法.我的困惑是,我认为EJB必须在EJB容器中有一个本地或远程接口.但是在我的示例中,我根本不需要接口,并且能够直接调用EJB,而我认为我至少需要一个本地接口?

I'm created a Java EE application and added a stateless session bean to the EJB project. The EJB project is a dependency in the web/WAR project, and I inject the EJB I created in the EJB project, in one of my servlets. This works fine and I'm able to deploy and call the methods of this EJB in the servlet of the web application project. My confusion was that, I thought EJBs had to have an interface in the EJB container, where they were either local or remote. However in my example, I didn't need an interface at all and was able to call the EJB directly where I thought I would need a local interface at least?

推荐答案

从EJB 3.1开始,您不再需要用于本地服务的EJB接口.带有 @Stateless @Stateful @Singleton 的任何POJO类都将是企业会话Bean.

Since EJB 3.1 you don't need the EJB interfaces for local services anymore. Any POJO class annotated with @Stateless, @Stateful or @Singleton will be an enterprise session bean.

返回自然合同一类合同包括以下所有内容:它的公共方法.公用方法旨在供他们的客户.Enterprise JavaBeans 3.1的无接口视图Bean的定义与EJB 3.1的3.4.4章完全相同.规范(JSR 318):

Back to the Natural Contract The contract of a class comprises all of its public methods. The public methods are intended to be used by their clients. The no-interface view of an Enterprise JavaBeans 3.1 bean is defined exactly as follows in Chapter 3.4.4 of the EJB 3.1 specification (JSR 318):

………会话Bean的无接口视图是本地视图的变体在不使用的情况下公开bean类的公共方法单独的业务界面..."

"…A Session Bean’s no-interface view is a variation of the Local view that exposes the public methods of the bean class without the use of a separate business interface…"

所有私有方法都被隐藏.使用package-private和受保护的可见性仅对同一包中的类可见并且通常仅出于测试目的对其进行访问.JUnit测试该类与测试中的类"(CUT)位于同一包中,并且模拟出不便的引用,通常访问直接打包私有或受保护的字段.

All private methods are hidden. Methods with package-private and protected visibility are visible only to classes in the same package and they are usually accessed only for test purposes. A JUnit test class resides in the same package as the "Class Under Test" (CUT) and mocks-out the inconvenient references, usually accessing the package-private or protected fields directly.

检查: http://www.oracle.com/technetwork/article/java/intondemand-1444614.html

这篇关于EJB企业应用程序不需要EJB接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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