---
title: "通过注解方式@EJB注入和JNDI查找方式并使用其他EJB或者服务"
author: "javaEEdevelop"
date: "2013-03-21T08:31:55Z"
tags: []
categories: ["开源软件"]
slug: "ejb-jndi-ejb"
draft: false
lastmod: "2013-03-21T08:31:55Z"
id: 1830721
url: "https://javaeedevelop.iteye.com/blog/1830721"
---

1.通过JNDI查找方式来查找其他的bean  
InitialContext ctx = new InitialContext();  
HelloWorld helloworld = (HelloWorld) ctx  
.lookup("实现类的简单名称/remote");

 2.通过注解@EJB  
 例如  
 @EJB Other other;//现在就可以使用Other里面的公共方法了,条件是Other必须是一个EJB对像  
 @Resource TimeService TimeService;//注入其他的对象,比如EJB3中TimeService类,@Resource类路径是javax.anontation.Resource;