有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JNDI查找异常无法获得到这些URL中任何URL的连接:localhost和发现失败,出现错误

我说的是我大学里的一个JAVA EJB-WEB应用项目。在我发布之前,我尝试了任何方法来解决这个问题

我在调试模式下运行它,得到的一行是异常:

QueueConnectionFactory f = (QueueConnectionFactory)ctx.lookup("ConnectionFactory");

当我遇到这个可怕的异常时,我正试图查找JNDI。 我不知道为什么。我尝试过更改端口,将提供者的URL更改为许多选项,但仍然不起作用。我每次都会犯同样的错误

这是类-BusinessDelegate,其中是JNDI获取的is属性:

public class BusinessDelegate {
    private QueueSession qsession;
    private QueueSender qsender;
    private IncomeService incomeService;

    public BusinessDelegate(){
        // Prepare initial context

//      Hashtable<String,String> jndiProperties = new Hashtable<String,String>();
        Properties jndiProperties = new Properties();
        jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
//      jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
        jndiProperties.put(Context.PROVIDER_URL,"localhost");
//      jndiProperties.put(Context.PROVIDER_URL,"http://0.0.0.0");
//      jndiProperties.put("jboss.naming.client.ejb.context", true);
        try
        {
            // Set initial context
            InitialContext ctx = new InitialContext(jndiProperties);
            // Set the rest of connection properties
            QueueConnectionFactory f = (QueueConnectionFactory)ctx.lookup("ConnectionFactory");
            Queue q = (Queue)ctx.lookup("queue/couponQueue");
            incomeService = (IncomeService)ctx.lookup("incomeService/local");
            QueueConnection qcon = f.createQueueConnection();
            qsession = qcon.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
            qsender = qsession.createSender(q);
            ctx.close();
        }catch(Exception e){
            // for testing..
            System.out.println("Something went wrong! in + [" + this.getClass().getSimpleName() + "] Class-Construrctor");
            e.printStackTrace();
        }   
    }

    public synchronized void storeIncome(Income i){
        try{
            qsender.send(qsession.createObjectMessage(i));
        }catch(Exception e){
            System.out.println("Income persistance failed");
            e.printStackTrace();
        }
    }

    public Collection<Income> viewAllIncome(){
        return incomeService.viewAllIncome();
    }

    public Collection<Income> viewIncomeByCompany(long id){
        return incomeService.viewIncomeByCompany(id);
    }

    public Collection<Income> viewIncomeByCustomer(long id){
        return incomeService.viewIncomeByCustomer(id);
    }
}

如果有必要,我可以让你完全访问GitHub中的项目


共 (0) 个答案