ビジネスインターフェース無しのEJBを作る場合は@LocalBeanアノテーションをつけたほうが良い

昨日書いた記事は記載が足りていませんでした。

EJBのJSR(4.9.8 Session Bean’s No-Interface View)を確認したところ、EJBのビジネスインターフェースを作らなくて良い条件は以下の3つのいずれかを満たす必要があるそうです。

  1. If the bean does not expose any other client views (Local, Remote, No-Interface, 2.x Remote Home, 2.x Local Home, Web Service) and its implements clause is empty, the bean defines a no-interface view.
  2. If the bean exposes at least one other client view, the bean designates that it exposes a no-interface view by means of the @LocalBean annotation on the bean class or in the deployment descriptor.
  3. The following interfaces are excluded when determining whether the bean exposes a no-interface view : java.io.Serializable; java.io.Externalizable; any of the interfaces defined by the javax.ejb package.

一番目はEJB2.0の名残のため置いておくとして、2番目と3番目を端折って書けば、特定のインターフェース以外をimplimentsしていないこと、もしくは@LocalBeanアノテーションがついていることがビジネスインターフェースを省略できる条件のようです。

@Stateless
@LocalBean
public class EJBImpl {
    public void doSomething() {
    }  
}


public class EJBExecutorServlet extends HttpServlet {
    @EJB //呼び出し側では実装を指定してインジェクションする
    EJBImpl ejb;

前回のコードに@LocalBeanを付けてみたら見事に動きました。
ぐぬぬ
https://github.com/megascus/CannotExecuteEJBWithInterface

今まで自分はEJB3.1を書く時は単純に@Stateless/@Statefulアノテーションだけつけていましたが、@LocalBeanもつけるようにしたほうが不要な不具合を避ける事ができてよさそうですね。

さて、これでGroovyでEJBを作れるかというとそうは問屋がおろさなかった・・・・
続きは次回。

参考
http://download.oracle.com/otndocs/jcp/ejb-3.1-fr-eval-oth-JSpec/
http://stackoverflow.com/questions/10889563/ejb-3-1-localbean-vs-no-annotation