EJB 企业应用程序不需要 EJB 接口
EJB enterprise application doesn't need EJB interface
我创建了一个 Java EE 应用程序并向 EJB 项目添加了一个无状态会话 bean。 EJB 项目是 web/WAR 项目中的依赖项,我将在 EJB 项目中创建的 EJB 注入到我的一个 servlet 中。这工作正常,我能够在 Web 应用程序项目的 servlet 中部署和调用此 EJB 的方法。我的困惑是,我认为 EJB 必须在 EJB 容器中有一个接口,它们要么在本地,要么在远程。但是在我的示例中,我根本不需要接口,并且能够在我认为至少需要本地接口的地方直接调用 EJB?
从 EJB 3.1 开始,您不再需要用于本地服务的 EJB 接口。任何用 @Stateless、@Stateful 或 @Singleton 注释的 POJO class 将是一个企业会话 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):
“…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…”
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/articles/java/intondemand-1444614.html
我创建了一个 Java EE 应用程序并向 EJB 项目添加了一个无状态会话 bean。 EJB 项目是 web/WAR 项目中的依赖项,我将在 EJB 项目中创建的 EJB 注入到我的一个 servlet 中。这工作正常,我能够在 Web 应用程序项目的 servlet 中部署和调用此 EJB 的方法。我的困惑是,我认为 EJB 必须在 EJB 容器中有一个接口,它们要么在本地,要么在远程。但是在我的示例中,我根本不需要接口,并且能够在我认为至少需要本地接口的地方直接调用 EJB?
从 EJB 3.1 开始,您不再需要用于本地服务的 EJB 接口。任何用 @Stateless、@Stateful 或 @Singleton 注释的 POJO class 将是一个企业会话 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):
“…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…”
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/articles/java/intondemand-1444614.html