はじめに

OSGi な Session Bean の JNDI 名 はどう決まるのか?

OSGi な Session Bean の JNDI 名 はどう設定するのか?

Interface

@Local
public interface Hello {
    String JNDI_NAME = "java:global/ejb/com.foo.snail.api.Hello/v1.0";
    String sayHello(String name);
}

SessionBean?

@Stateless
@EJB(name = Hello.JNDI_NAME, beanInterface = Hello.class)
public class HelloEjb implements Hello {
    @Override
    public String sayHello(final String name) {
        return "Hello " + name;
    }
}

EJB Client (Servlet)

@WebServlet(name = "HelloServlet", urlPatterns = {"/hello"})
public class HelloServlet extends HttpServlet {

    @EJB(lookup = Hello.JNDI_NAME)
    private Hello hello;
        
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Hello</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println(hello.sayHello(req.getParameter("NAME")));
        } catch (Exception ex) {
            out.println("<pre>");
            ex.printStackTrace(out);
            out.println("</pre>");
        } finally {
            out.println("</body>");
            out.println("</html>");
            out.close();
        }
    }
}

Java#Glassfish


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2015-01-07 (水) 21:37:31 (3641d)
Short-URL: http://at-sushi.com/pukiwiki/index.php?cmd=s&k=60e5464ea7
ISBN10
ISBN13
9784061426061