2015-10-29 87 views
0

我使用JBOSS Develper Studio 8,基於jre 1.7的JBOS服務器7.1我有一個ejb(DnenvikEJB)和web項目(DnevnikWEB)的J2EE項目(名稱爲Dnevnik)。我想通過jndi查找從servlet調用ejb。 EJB的名字是FasadaPrvi,他的遠程接口是FasadaPrviRemote。我對所有這些代碼變體都有問題:從servlet調用EJB

InitialContext context = new InitialContext(); 
FasadaPrvi fasadaPrvi = (FasadaPrvi)context.lookup("java:comp/env/FasadaPrvi"); 

InitialContext context = new InitialContext(); 
FasadaPrvi fasadaPrvi = (FasadaPrvi)context.lookup("java:app/DnevnikEJB/FasadaPrvi"); 

InitialContext context = new InitialContext(); 
FasadaPrvi fasadaPrvi = (FasadaPrvi)context.lookup("java:global/DnevnikEJB/FasadaPrvi"); 

InitialContext context = new InitialContext(); 
FasadaPrvi fasadaPrvi = (FasadaPrvi)context.lookup("java:global/Dnevnik/DnevnikEJB/FasadaPrvi!sr.co.FasadaPrviRemote"); 

有人知道問題出在哪裏!

回答

0

從JBoss維基:https://docs.jboss.org/author/display/AS71/JNDI+Reference https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project

Context ctx = new InitialContext(jndiProps); 
// lookup the bean  Foo 
beanRemoteInterface = (Foo) ctx.lookup("myapp/myejbmodule/FooBean!org.myapp.ejb.Foo"); 
String bar = beanRemoteInterface.sayBar(); 

和:

ejb:myapp/myejbjar/MyEjbName!com.test.MyRemoteInterface 
ejb:myapp/myejbjar/MyStatefulName!comp.test.MyStatefulRemoteInterface?stateful 

此外,EJB的部署過程中,Jboss的說明你與JNDI的名字你的豆子是可見的信息。

09:25:07,852 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named RegistrationService in deployment unit subdeployment "MY_EJB-15.99.00.war" of deployment "MY_EAR-15.00.ear" are as follows: 

    java:global/MY_EAR-15.00/MY_EJB-15.00/RegistrationService!foo.RegistrationService 
    java:app/MY_EJB-15.00/RegistrationService!foo.RegistrationService 
    java:module/RegistrationService!foo.RegistrationService 
    java:global/MY_EAR-15.00/MY_EJB-15.00/RegistrationService 
    java:app/MY_EJB-15.00/RegistrationService 
    java:module/RegistrationService