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?
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.
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.
Check: http://www.oracle.com/technetwork/articles/java/intondemand-1444614.html