我正在使用wildfly 10。
由于某种原因,我遇到了这样的错误:
javax.naming.NameNotFoundException: ServiceAImpl-- service jboss.naming.context.java.global.ServiceAImpl: javax.naming.NameNotFoundException: ServiceAImpl -- service
我访问jndi的方式:
InitialContext initialContext = new InitialContext();
Context context = (Context) initialContext.lookup("java:global/");
IWorker worker = (IWorker) context.lookup("ServiceAImpl");
worker.createTimer(task);
其余代码:
public interface IWorker{
void createTimer(ExecutableTask aExecutableTask);
}
@Stateless
@Local(IServiceA.class)
public class IServiceAImpl
implements IServiceA {
@Override
public void createTimer(ExecutableTask aExecutableTask) {
System.out.println("I am doing some jobs");
}
}
@Local
public interface IServiceAextends IWorker{
}
如何获得对此IWorker的访问权限?如何获得此JNDI?
答案 0 :(得分:0)
看看here。启动后,您将在Wildfly日志中找到与此类似的内容。
<div>
<div id="com4" class="md" value="7-10">yellow
<a onclick="toggle(4, 7, 10)" href="javascript:void(0)">[-]</a>
</div>
<div id="com5" class="md">Should not collapse</div>
<div id="com8" class="md">Should collapse</div>
<div id="com9" class="md">Should collapse</div>
<div id="com11" class="md">Should not collapse</div>
</div>
因此,就像上面的示例一样,您可以在控制台日志中找到所需的JNDI。在这种情况下,您几乎已经存在了,但是您必须使用完整的信息来完成这段代码:
java:global/<your-project>/bus-facade-fumo/WUFFacade!<your-project>.wuf.WUFFacadeRemote
java:app/bus-facade-<your-project>/WUFFacade!<your-project>.wuf.WUFFacadeRemote
java:module/WUFFacade!<your-project>.wuf.WUFFacadeRemote
java:jboss/exported/<your-project>/bus-facade-<your-project>/WUFFacade!<your-project>.wuf.WUFFacadeRemote
java:global/<your-project>/bus-facade-<your-project>/WUFFacade
java:app/bus-facade-<your-project>/WUFFacade
java:module/WUFFacade