How to solve portable jndi name problem in unit tests?
I am using javaee6/ejb3.1 api with glassfish embedded server. my application structure is ui-controller module ejbs calls biz-controller ejbs. with the global jndi name format is java:global/myapp/mymodule/myejb.
But when I try to unit test both modules without packaging application on embedded server; get different application name for jndi which is related to temp folder ...
Please find the console log here..
The jndi names generated are like..
java:global/ejb-app1138741107347091524/controllers/ArticleService
every time I run the test
java:global/ejb-appXXXXXXXXXXXXXXXXXX/controllers/ArticleService
XXXXXXXX in ejb-app name in jndi name gets changed...
FINE: [Application] -C:-DOCUME~1-daunddig-LOCALS~1-Temp-ejb-app1138741107347091524- , uid: 84898074169442304
Jan 19, 2011 6:26:46 PM com.sun.enterprise.deployment.Application setUniqueId
FINE: Ejb classes.jar:ArticleFacadeImpl id = 84898074169442304
Jan 19, 2011 6:26:46 PM com.sun.enterprise.deployment.Application setUniqueId
FINE: Ejb controllers-0_0_1-SNAPSHOT.jar:ArticleService id = 84898074169442305
Jan 19, 2011 6:26:46 PM com.sun.ejb.containers.BaseContainer initializeHome
INFO: Portable JNDI names for EJB ArticleFacadeImpl : [java:global/ejb-app1138741107347091524/ui-boundaries/ArticleFacadeImpl!dd.ecb.jee6.fa
cades.ArticleFacade, java:global/ejb-app1138741107347091524/ui-boundaries/ArticleFacadeImpl]
Jan 19, 2011 6:26:46 PM com.sun.ejb.containers.开发者_运维百科BaseContainer initializeHome
INFO: Portable JNDI names for EJB ArticleService : [java:global/ejb-app1138741107347091524/controllers/ArticleService!dd.ecb.jee6.services.i
mpl.ArticleService, java:global/ejb-app1138741107347091524/controllers/ArticleService]
solved the issue by configuring applciation name at the time of creating ejb container in javase code...
prop.put(javax.ejb.embeddable.EJBContainer.APP_NAME, "ecb-app");
facade = (ArticleFacade)EJBContainer.createEJBContainer(prop).getContext().lookup("java:global/ecb-app/ui-boundaries/ArticleFacadeImpl");
精彩评论