JNDI查找异常 - 无法获取与这些URL中的任何URL的连接:localhost和discovery因错误而失败

时间:2016-12-12 22:26:43

标签: java jboss wildfly jndi

我正在谈论我大学的JAVA EJB-WEB APP项目。到目前为止,我尝试了任何解决此问题的方法。

我用Debug模式运行它,我得到的这行是异常:

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

当我遇到这个可怕的异常时,我试图查找JNDI。 我不知道为什么。我尝试更改PORT,将PROVIDER_URL更改为很多选项,但仍然无法正常工作。我每次都得到同样的错误。

这是Class - BusinessDelegate,JNDI获取的是属性:

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 个答案:

没有答案