2011-11-23 74 views
1

我試圖通過使用JNDI命名實現ejb調用。JNDI查找只返回「javax.naming.NameNotFoundException」

設置:

  • JBoss-6.1.0.Final
  • 耳部署:
    • gwt.war
    • ejb.jar

我的問題是,儘管JNDIView顯示我現有的ejb,但我無法達到它。

在我的RemoteServiceServlet中,我嘗試訪問ejb,該ejb部署在同一個ear-package中的ejb.jar中。

我已經嘗試了幾次電話,因爲我不確定正確的jndi代碼。

try 
{ 
    productLocal = (ProductLocal) context.lookup("ProductHome/local"); 
} 
catch (NamingException e) 
{ 
    System.err.println(e.getMessage()); 
    e.printStackTrace(); 
} 

也試過:

productLocal = (ProductLocal) context.lookup("ProductLocal"); 
productLocal = (ProductLocal) context.lookup("sung_app_kylintv/ProductHome/local"); 

無狀態EJB是這樣分配:

@Stateless 
@Local(ProductLocal.class) 
@Remote(ProductRemote.class) 
@LocalBinding(jndiBinding="ProductLocal") 
@RemoteBinding(jndiBinding="ProductRemote") 
public class ProductHome extends HomeBase<ProductEntity> implements SessionBean, Serializable, ProductLocal 

啓動上下文

Properties p = new Properties(); 
p.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"); 
p.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); 
p.put("java.naming.provider.url","jnp://localhost:1099"); 

context = new InitialContext(p); 

關於JNDIView

+- sung_app_kylintv (class: org.jnp.interfaces.NamingContext) 
    | +- CategoryHome (class: org.jnp.interfaces.NamingContext) 
    | | +- local (class: Proxy for: sung.app.kylintv.ejbclient.product.CategoryLocal) 
    | | +- local-sung.app.kylintv.ejbclient.product.CategoryLocal (class: Proxy for: sung.app.kylintv.ejbclient.product.CategoryLocal) 
    | | +- remote-sung.app.kylintv.ejbclient.product.CategoryRemote (class: Proxy for: sung.app.kylintv.ejbclient.product.CategoryRemote) 
    | | +- remote (class: Proxy for: sung.app.kylintv.ejbclient.product.CategoryRemote) 
    | +- ProductHome (class: org.jnp.interfaces.NamingContext) 
    | | +- local (class: Proxy for: sung.app.kylintv.ejbclient.product.ProductLocal) 
    | | +- remote (class: Proxy for: sung.app.kylintv.ejbclient.product.ProductRemote) 
    | | +- remote-sung.app.kylintv.ejbclient.product.ProductRemote (class: Proxy for: sung.app.kylintv.ejbclient.product.ProductRemote) 
    | | +- local-sung.app.kylintv.ejbclient.product.ProductLocal (class: Proxy for: sung.app.kylintv.ejbclient.product.ProductLocal) 
    | +- CustomerHome (class: org.jnp.interfaces.NamingContext) 
    | | +- local-sung.common.behavior.FindAllBehaviour (class: Proxy for: sung.common.behavior.FindAllBehaviour) 
    | | +- local (class: Proxy for: sung.common.behavior.FindAllBehaviour) 
    | +- Option (class: org.jnp.interfaces.NamingContext) 
    | | +- local-sung.app.kylintv.ejbclient.product.OptionLocal (class: Proxy for: sung.app.kylintv.ejbclient.product.OptionLocal) 
    | | +- local (class: Proxy for: sung.app.kylintv.ejbclient.product.OptionLocal) 
    | | +- remote-sung.app.kylintv.ejbclient.product.OptionRemote (class: Proxy for: sung.app.kylintv.ejbclient.product.OptionRemote) 
    | | +- remote (class: Proxy for: sung.app.kylintv.ejbclient.product.OptionRemote) 
    | +- DurationHome (class: org.jnp.interfaces.NamingContext) 
    | | +- local (class: Proxy for: sung.app.kylintv.ejbclient.product.DurationLocal) 
    | | +- local-sung.app.kylintv.ejbclient.product.DurationLocal (class: Proxy for: sung.app.kylintv.ejbclient.product.DurationLocal) 
    | | +- remote (class: Proxy for: sung.app.kylintv.ejbclient.product.DurationRemote) 
    | | +- remote-sung.app.kylintv.ejbclient.product.DurationRemote (class: Proxy for: sung.app.kylintv.ejbclient.product.DurationRemote) 
    | +- VariantHome (class: org.jnp.interfaces.NamingContext) 
    | | +- local (class: Proxy for: sung.app.kylintv.ejbclient.product.VariantLocal) 
    | | +- local-sung.app.kylintv.ejbclient.product.VariantLocal (class: Proxy for: sung.app.kylintv.ejbclient.product.VariantLocal) 
    | | +- remote (class: Proxy for: sung.app.kylintv.ejbclient.product.VariantRemote) 
    | | +- remote-sung.app.kylintv.ejbclient.product.VariantRemote (class: Proxy for: sung.app.kylintv.ejbclient.product.VariantRemote) 
    | +- VelocityBean (class: org.jnp.interfaces.NamingContext) 
    | | +- local (class: Proxy for: sung.app.kylintv.ejb.velocity.Velocity) 
    | | +- local-sung.app.kylintv.ejb.velocity.Velocity (class: Proxy for: sung.app.kylintv.ejb.velocity.Velocity) 
    | +- CustomerAddressHome (class: org.jnp.interfaces.NamingContext) 
    | | +- local-sung.common.behavior.FindAllBehaviour (class: Proxy for: sung.common.behavior.FindAllBehaviour) 
    | | +- local (class: Proxy for: sung.common.behavior.FindAllBehaviour) 
    | +- OrderEntityHome (class: org.jnp.interfaces.NamingContext) 
    | | +- no-interface (class: sung.app.kylintv.ejbclient.order.OrderEntityHome_$$_javassist_50) 

有什麼要求JNDI來在這樣的情況下正常工作?

+0

'java:comp/env/ProductHome/local'? – EJP

回答

0

使用

productLocal = (ProductLocal) context.lookup("sung_app_kylintv/ProductHome/local") 

返回略有不同的錯誤信息:

2011-11-24 12:37:07,893 INFO [STDOUT] (http-0.0.0.0-8080-2) productLocal called successfully. 
2011-11-24 12:37:07,893 INFO [STDOUT] (http-0.0.0.0-8080-2) productLocal calling createTestEntry(). 
2011-11-24 12:37:07,950 ERROR [STDERR] (http-0.0.0.0-8080-2) org.jboss.injection.manager.spi.InjectionException: javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: sung not bound] 

我的一個同事後看了看錯誤已被確定:我嘗試使用@EJB內注射該類ProductHome,使用mappedName =「sung/...」。 mappedName是不正確的,甚至根本不需要,在ejb-project內連接已經存在並且工作。希望,這也可以幫助其他人。

解決方案: 我必須通過刪除我的ejb-call上的mappedName-Attribute來修復我的ProductHome。之後,類可以實例化並調用函數。