求助:HELLOWORLD EJB入門部署 折騰了3天了,吐血啊.
小弟不才,最近在研究EJB.開頭的例子HELLOWORLD..看了網上無數例子,總是無法跑通,很多例子本有就有問題.經過3天,終於部署成功,但是無法執行,JNDI出錯,實在沒有辦法了,網上找不到資料,請高手指點下迷途的羔羊.
第一個類:package examples;
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
public interface Hello extends EJBObject {
public String hello() throws RemoteException;
}
第二個類 package examples;
import javax.ejb.SessionContext;
public class HelloBean implements javax.ejb.SessionBean {
private SessionContext ctx;
public void ejbCreate() {
System.out.print("ejbCreate()");
}
public void ejbRemove() {
System.out.print("ejbRemove()");
}
public void ejbActivate() {
System.out.print("ejbActivate()");
}
public void ejbPassivate() {
System.out.print("ejbPassivate");
}
public void setSessionContext(javax.ejb.SessionContext ctx) {
this.ctx = ctx;
}
public String hello() {
System.out.print("hello()");
return "Hello World~!";
}
}
第三個類:package examples;
public interface HelloHome extends javax.ejb.EJBHome{
Hello create()throws java.rmi.RemoteException,javax.ejb.CreateException;
}
XML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<Session>
<ejb-name>Hello</ejb-name>
<Home>examples.HelloHome</Home>
<Remote>examples.Hello</Remote>
<ejb-class>examples.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</Session>
</enterprise-beans>
</ejb-jar>
打包成HelloWorld.jar 放在JBOSS Deploy 資料夾下...然後執行測試檔案:
package examples;
import java.rmi.RemoteException;
import java.util.Properties;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class test {
public static void main(String args[]) throws NamingException, RemoteException, CreateException, RemoveException {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url","localhost:1099");
props.setProperty("java.naming.factory.url.pkgs","org.jboss.naming");
Context ctx = new InitialContext(props);
Object obj = ctx.lookup("HelloHome");
HelloHome Home = (HelloHome) javax.rmi.PortableRemoteObject.narrow(obj,
HelloHome.class);
Hello hello = Home.create();
System.out.print(hello.hello());
hello.remove();
}
}
部署成功了,但是測試一直出錯 Exception in thread "main" javax.naming.NameNotFoundException: HelloHome not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
實在是不行了,請罈子的高手們抽幾分鐘看下....已經痛苦3天了.
第一個類:package examples;
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
public interface Hello extends EJBObject {
public String hello() throws RemoteException;
}
第二個類 package examples;
import javax.ejb.SessionContext;
public class HelloBean implements javax.ejb.SessionBean {
private SessionContext ctx;
public void ejbCreate() {
System.out.print("ejbCreate()");
}
public void ejbRemove() {
System.out.print("ejbRemove()");
}
public void ejbActivate() {
System.out.print("ejbActivate()");
}
public void ejbPassivate() {
System.out.print("ejbPassivate");
}
public void setSessionContext(javax.ejb.SessionContext ctx) {
this.ctx = ctx;
}
public String hello() {
System.out.print("hello()");
return "Hello World~!";
}
}
第三個類:package examples;
public interface HelloHome extends javax.ejb.EJBHome{
Hello create()throws java.rmi.RemoteException,javax.ejb.CreateException;
}
XML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<Session>
<ejb-name>Hello</ejb-name>
<Home>examples.HelloHome</Home>
<Remote>examples.Hello</Remote>
<ejb-class>examples.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</Session>
</enterprise-beans>
</ejb-jar>
打包成HelloWorld.jar 放在JBOSS Deploy 資料夾下...然後執行測試檔案:
package examples;
import java.rmi.RemoteException;
import java.util.Properties;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class test {
public static void main(String args[]) throws NamingException, RemoteException, CreateException, RemoveException {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url","localhost:1099");
props.setProperty("java.naming.factory.url.pkgs","org.jboss.naming");
Context ctx = new InitialContext(props);
Object obj = ctx.lookup("HelloHome");
HelloHome Home = (HelloHome) javax.rmi.PortableRemoteObject.narrow(obj,
HelloHome.class);
Hello hello = Home.create();
System.out.print(hello.hello());
hello.remove();
}
}
部署成功了,但是測試一直出錯 Exception in thread "main" javax.naming.NameNotFoundException: HelloHome not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
實在是不行了,請罈子的高手們抽幾分鐘看下....已經痛苦3天了.
相關文章
- 為了更好的“玩電影”,遊戲行業已折騰了40年遊戲行業
- 折騰了幾天,一款至簡的 hexo 主題Hexo
- 繩命在於折騰,我用 Nuxt.js 重構了部落格UXJS
- node HelloWorld入門篇
- iOS-入門HelloWorldiOS
- 本人學習了ejb,
- Linux折騰Linux
- 折騰日記
- waydroid折騰
- React入門-1.helloworldReact
- 週末折騰了兩天,踩了無數個坑,終於把win7裝成了centos7Win7CentOS
- 如何自動化部署專案?折騰伺服器之旅~伺服器
- Netty5 入門HelloWorldNetty
- Zookeeper入門-Java版本HelloWorld例子Java
- Hackintosh (黑蘋果) 折騰蘋果
- 折騰樹莓派樹莓派
- 不要太折騰程式
- UGNX折騰筆記筆記
- 【折騰】github+jekyll搭建靜態網站(還沒折騰完),折騰不下去了,求解救Github網站
- 《ECMAScript 6入門》上線了
- 小白折騰伺服器(一):docker 搭建 lnmp+ 使用 deployer 部署伺服器DockerLNMP
- 入門Semantic Kernel:OneApi整合與HelloWorldAPI
- nvim 折騰筆記 2筆記
- 行啊,人工智慧玩大了!人工智慧
- 折戟IPO,Soul遭遇了什麼?
- golang 快速入門 [3]-go 語言 helloworldGolang
- VS Code折騰記 - (1)扯淡
- 折騰oracle的em3Oracle
- 折騰oracle的em2Oracle
- 折騰oracle的em1Oracle
- hexo fluid主題折騰HexoUI
- (求助)用過 ip route 的請了(轉)
- Zookeeper入門一篇就夠了
- RabbitMQ入門,我是動了心的MQ
- 入門Webpack,看這篇就夠了Web
- Zookeeper入門看這篇就夠了
- React入門看這篇就夠了React
- intellij配置EJB專案入門IntelliJ