简体   繁体   English

EJB 企业应用不需要 EJB 接口

[英]EJB enterprise application doesn't need EJB interface

I'm created a Java EE application and added a stateless session bean to the EJB project.我创建了一个 Java EE 应用程序并向 EJB 项目添加了一个无状态会话 bean。 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. EJB 项目是 web/WAR 项目中的一个依赖项,我将在 EJB 项目中创建的 EJB 注入到我的一个 servlet 中。 This works fine and I'm able to deploy and call the methods of this EJB in the servlet of the web application project.这工作正常,我能够在 Web 应用程序项目的 servlet 中部署和调用此 EJB 的方法。 My confusion was that, I thought EJBs had to have an interface in the EJB container, where they were either local or remote.我的困惑是,我认为 EJB 必须在 EJB 容器中有一个接口,它们要么是本地的,要么是远程的。 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?

Since EJB 3.1 you don't need the EJB interfaces for local services anymore.从 EJB 3.1 开始,您不再需要本地服务的 EJB 接口。 Any POJO class annotated with @Stateless , @Stateful or @Singleton will be an enterprise session bean.任何用@Stateless@Stateful@Singleton注释的 POJO 类都将是企业会话 bean。

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): Enterprise JavaBeans 3.1 bean 的无接口视图在 EJB 3.1 规范 (JSR 318) 的第 3.4.4 章中定义如下:

“…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…” “……会话 Bean 的无接口视图是本地视图的变体,它公开了 Bean 类的公共方法,而无需使用单独的业务接口……”

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. JUnit 测试类与“被测类”(CUT)位于同一个包中,并模拟出不方便的引用,通常直接访问包私有或受保护的字段。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM