1 OpenEJB概述
Tomcat本不支持部署EJB,通过向其安装OpenEjb,可使其支持。
2 安装
2.1 下载
http://www.apache.org/dyn/closer.cgi/openejb/3.1.3/openejb.war
2.2 安装
1、将下载的openejb.war 放在Tomcat的安装目录 webapps下。
2、启动Tomcat。
3、在IE中输入:http://localhost:8080/openejb 回车后显示如下信息:
Welcome to the OpenEJB/Tomcat integration!
Now that OpenEJB has been installed, click on the "Testing your setup" link below to verify it. When everything is setup well, feel free to play around with the tools provided below!
OK!安装成功,就这么简单!
4、测试一下:http://localhost:8080/openejb/viewjndi.jsp
3 部署
像往常一样,开发一个Ejb工程。
接口:
@Remote
public interface GreeterRemote
{
public String greet(String message);
public List<Greeting> getAllGreetings();
}
实现类:
@Stateless
public class GreeterBean implements GreeterRemote,GreeterLocal{
public List<Greeting> getAllGreetings(){
List<Greeting> greetings = new ArrayList<Greeting>();
Greeting greeting = new Greeting();
greeting.setId(12);
greeting.setName("bill gates");
greetings.add(greeting);
greeting = new Greeting();
greeting.setId(334);
greeting.setName("李宁");
greetings.add(greeting);
return greetings;
}
public String greet(String message){
return "您好"+ message;
}
}
将此EJB工程打成jar包,比如放在D:\Tomcat\ejb下。注:“D:\Tomcat\ejb”是我自己建的。
然后打开:Tomcat\conf\openejb.xml,将</openejb>前的内容改为:
<!--
#
# The <Deployments> element can be used to configure file
# paths where OpenEJB should look for ejb jars or ear files.
#
# See http://openejb.apache.org/deployments.html
#
# The below entry is simply a default and can be changed or deleted
<Deployments dir="apps/" />原来是这句,我们用不到,可以用下面的语句直接加载指定的ejb jar包。
-->
<Deployments jar="D:/Tomcat/ejb/OpenEjbTest.jar" />
重启Tomcat,在浏览器输入:http://127.0.0.1:8089/openejb/invokeobj.jsp
点击其中的”Browse for an EJB”,转到如下界面:
如果在其中能看到自己的EJB Bean,那就成功了。
4 客户端调用
按照官方给出的说明:http://openejb.apache.org/3.0/clients.html,此处使用“Remote Client with HTTP (in tomcat)”方式。对上面部署的EJB调用的客户端代码如下:
public class GreeterBeanTest{
public static void main(String[] args) throws NamingException {
Properties p = new Properties();
p.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
p.put("java.naming.provider.url", "http://localhost:8089/openejb/ejb");
InitialContext initialContext = new InitialContext(p);
GreeterRemote greeterRemote =(GreeterRemote) initialContext.lookup("GreeterBeanRemote");
String str="屈剑峰";
System.out.println(greeterRemote.greet(str));
}
}
分享到:
相关推荐
OpenEJB 提供了强大的测试工具,例如,可以使用 `openejb-test` 模块进行单元测试和集成测试。在示例中,你可以学习如何编写和运行这些测试。 通过深入研究这个“openejb-examples-3.0”压缩包中的项目,开发者...
目前Tomcat并不直接支持EJB,但可借助openejb插件来间接能够支持EJB
标题中的"openejb-embedded-maven-plugin-4.6.0.1.zip"是一个开源项目的Maven插件包,特别地,它是OpenEJB的嵌入式版本。OpenEJB是一个开源的企业JavaBeans(EJB)容器和服务器,它实现了Java EE(现在称为Jakarta ...
标签:arquillian-openejb-embedded-4-4.7.0-javadoc.jar,arquillian,openejb,embedded,4,4.7.0,javadoc,jar包下载,依赖包
标签:arquillian-openejb-embedded-4-4.5.1-sources.jar,arquillian,openejb,embedded,4,4.5.1,sources,jar包下载,依赖包
标签:arquillian-openejb-embedded-4-4.5.2-javadoc.jar,arquillian,openejb,embedded,4,4.5.2,javadoc,jar包下载,依赖包
标签:arquillian-openejb-embedded-4-4.6.0-javadoc.jar,arquillian,openejb,embedded,4,4.6.0,javadoc,jar包下载,依赖包
标签:arquillian-openejb-embedded-4-4.6.0-sources.jar,arquillian,openejb,embedded,4,4.6.0,sources,jar包下载,依赖包
标签:arquillian-openejb-embedded-4-4.5.2-sources.jar,arquillian,openejb,embedded,4,4.5.2,sources,jar包下载,依赖包
标签:arquillian-openejb-embedded-4-4.7.1-javadoc.jar,arquillian,openejb,embedded,4,4.7.1,javadoc,jar包下载,依赖包
标签:arquillian-openejb-embedded-4-4.7.1-sources.jar,arquillian,openejb,embedded,4,4.7.1,sources,jar包下载,依赖包
标签:arquillian-openejb-embedded-4-4.7.0-sources.jar,arquillian,openejb,embedded,4,4.7.0,sources,jar包下载,依赖包
标签:arquillian-openejb-embedded-4-4.5.0-javadoc.jar,arquillian,openejb,embedded,4,4.5.0,javadoc,jar包下载,依赖包
标签:arquillian-openejb-embedded-4-4.5.0-sources.jar,arquillian,openejb,embedded,4,4.5.0,sources,jar包下载,依赖包
标签:arquillian-openejb-embedded-4-4.5.1-javadoc.jar,arquillian,openejb,embedded,4,4.5.1,javadoc,jar包下载,依赖包
标签:arquillian-openejb-transaction-provider-1.7.0.jar,arquillian,openejb,transaction,provider,1.7.0,jar包下载,依赖包
标签:arquillian-openejb-embedded-4-4.5.2.jar,arquillian,openejb,embedded,4,4.5.2,jar包下载,依赖包
标签:arquillian-openejb-transaction-provider-1.5.1.jar,arquillian,openejb,transaction,provider,1.5.1,jar包下载,依赖包
标签:arquillian-openejb-embedded-4-4.6.0.jar,arquillian,openejb,embedded,4,4.6.0,jar包下载,依赖包