Javax.naming.namenotfoundexcep ... [英] Javax.naming.namenotfoundexcep...

查看:66
本文介绍了Javax.naming.namenotfoundexcep ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在堆栈跟踪中遇到异常:



 20:00:08,105 ERROR [stderr](DefaultQuartzScheduler_Worker-1)javax .naming.NameNotFoundException:java:comp / env 
20:00:08,111 ERROR [stderr](DefaultQuartzScheduler_Worker-1)at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:121)
20:00:08,124 ERROR [stderr](DefaultQuartzScheduler_Worker-1)at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
20:00:08,124 ERROR [stderr](DefaultQuartzScheduler_Worker- 1)在javax.naming.InitialContext.lookup(InitialContext.java:411)
20:00:08,124 ERROR [stderr](DefaultQuartzScheduler_Worker-1)at com.comsats.cibs.db.conn.ConnectionPool.getConnection( ConnectionPool.java:99)
20:00:08,124错误[stderr](DefaultQuartzScheduler_Worker-1)at com.comsats.cibs.db.conn.CIBSPoolManager.getConnection(CIBSPoolManager.java:57)
20 :00:08,124 com.comsats.cibs.db中的ERROR [stderr](DefaultQuartzScheduler_Worker-1)。 dao.sysmngmt.NodeDaoMySqlImpl.getAllNodes(NodeDaoMySqlImpl.java:51)
20:00:08,124错误[stderr](DefaultQuartzScheduler_Worker-1)at com.comsats.cibs.db.dao.sysmngmt.SysMngmntFacade.getAllNodes(SysMngmntFacade) .java:874)
20:00:08,124错误[stderr](DefaultQuartzScheduler_Worker-1)at com.comsats.cibs.schedular.InvoiceGeneration.execute(InvoiceGeneration.java:31)
20:00: 08,124 ERROR [stderr](DefaultQuartzScheduler_Worker-1)atg.quartz.core.JobRunShell.run(JobRunShell.java:202)
20:00:08,124 org.quartz的ERROR [stderr](DefaultQuartzScheduler_Worker-1)。 simpl.SimpleThreadPool $ WorkerThread.run(SimpleThreadPool.java:573)





我尝试过:



我正在运行一个调度程序,我正在调用数据库:



  @覆盖 
public void 执行(JobExecutionConte xt arg0) throws JobExecutionException {
synchronized 字符串 class ){
CIBSInvoiceGenerationTimer ci = new CIBSInvoiceGenerationTimer();
InvoiceTransationManager it = new InvoiceTransationManager();
Iterator nodes = null;
SysMngmntFacade sysFacade = SysMngmntFacade.getInstance();

try {
nodes = sysFacade.getAllNodes();
} catch (SQLException e1){
// TODO自动生成的捕获块
e1.printStackTrace();
} catch (NoRecordsFoundException e1){
// TODO自动生成的捕获块
e1.printStackTrace();
} catch (例外e1){
// TODO自动生成的捕获块
e1.printStackTrace();
}
}
}





getAllNodes连接到数据库,如:



 CIBSPoolManager poolManager = CIBSPoolManager.getInstance(); 
连接connect = poolManager.getConnection( mysql);





比getConnection:





  public 连接getConnection( String  name){

conn = pool.getConnection();
return conn;
}





然后在pool.getConnection



< pre lang =java> public Connection getConnection()
{
InitialContext initContext = null;
上下文envContext = null;
DataSource ds = null;
连接conn = null;
尝试 {
initContext = new InitialContext();
} catch (NamingException e3){
// TODO自动生成的捕获块
e3.printStackTrace();
}

尝试 {
envContext =(Context)initContext.lookup( java:comp / env);
} catch (NamingException e2){
// TODO自动生成的捕获块
e2.printStackTrace();
}

尝试 {
ds =(DataSource)envContext.lookup( cibsmysql);
} catch (NamingException e1){
// TODO自动生成的捕获块
e1.printStackTrace();
}

尝试 {
conn = ds.getConnection();
} catch (SQLException e){
// TODO自动生成的捕获块
e.printStackTrace();
}
System.out.println( 获取连接);
return conn;
}





我在项目的每个地方都使用过此代码并且工作正常。但是现在我想制定一个调度程序来运行一些代码,但是在调度时我来到这个行:



 envContext =(Context )initContext.lookup(  java:comp / env); 





有人可以指导我。很明显,不连接的原因可能是因为这个调度,但我无法弄清楚原因和解决方案。我也在其他论坛上问过但没有答案。需要帮助:(

解决方案

WorkerThread.run(SimpleThreadPool.java:573)





我尝试过:



我正在运行一个调度程序,我正在调用数据库:



  @ Override  
public void execute(JobExecutionContext arg0) throws JobExecutionException {
synchronized String class ){
CIBSInvoiceGenerationTimer ci = new CIBSInvoiceGenerationTimer();
InvoiceTransationManager it = new InvoiceTransationManager();
Iterator nodes = null;
SysMngmntFacade sysFacade = SysMngmntFacade.getInstance();

尝试 {
nodes = sysFacade.getAllNodes();
} catch (SQLException e1){
// TODO自动生成的捕获块
e1.printStackTrace();
} catch (NoRecordsFoundException e1){
// TODO自动生成的捕获块
e1.printStackTrace();
} catch (例外e1){
// TODO自动生成的捕获块
e1.printStackTrace();
}
}
}





getAllNodes连接到数据库,如:



 CIBSPoolManager poolManager = CIBSPoolManager.getInstance(); 
连接connect = poolManager.getConnection( mysql);





比getConnection:





  public 连接getConnection( String  name){

conn = pool.getConnection();
return conn;
}





然后在pool.getConnection



< pre lang =java> public Connection getConnection()
{
InitialContext initContext = null;
上下文envContext = null;
DataSource ds = null;
连接conn = null;
尝试 {
initContext = new InitialContext();
} catch (NamingException e3){
// TODO自动生成的捕获块
e3.printStackTrace();
}

尝试 {
envContext =(Context)initContext.lookup( java:comp / env);
} catch (NamingException e2){
// TODO自动生成的捕获块
e2.printStackTrace();
}

尝试 {
ds =(DataSource)envContext.lookup( cibsmysql);
} catch (NamingException e1){
// TODO自动生成的捕获块
e1.printStackTrace();
}

尝试 {
conn = ds.getConnection();
} catch (SQLException e){
// TODO自动生成的捕获块
e.printStackTrace();
}
System.out.println( 获取连接);
return conn;
}





我在项目的每个地方都使用过此代码并且工作正常。但是现在我想制定一个调度程序来运行一些代码,但是在调度时我来到这个行:



 envContext =(Context )initContext.lookup(  java:comp / env); 





有人可以指导我。很明显,不连接的原因可能是因为这个调度,但我无法弄清楚原因和解决方案。我也在其他论坛上问过但没有答案。需要帮助:(


I m getting an exception with stacktrace :

20:00:08,105 ERROR [stderr] (DefaultQuartzScheduler_Worker-1) javax.naming.NameNotFoundException: java:comp/env
20:00:08,111 ERROR [stderr] (DefaultQuartzScheduler_Worker-1)   at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:121)
20:00:08,124 ERROR [stderr] (DefaultQuartzScheduler_Worker-1)   at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
20:00:08,124 ERROR [stderr] (DefaultQuartzScheduler_Worker-1)   at javax.naming.InitialContext.lookup(InitialContext.java:411)
20:00:08,124 ERROR [stderr] (DefaultQuartzScheduler_Worker-1)   at com.comsats.cibs.db.conn.ConnectionPool.getConnection(ConnectionPool.java:99)
20:00:08,124 ERROR [stderr] (DefaultQuartzScheduler_Worker-1)   at com.comsats.cibs.db.conn.CIBSPoolManager.getConnection(CIBSPoolManager.java:57)
20:00:08,124 ERROR [stderr] (DefaultQuartzScheduler_Worker-1)   at com.comsats.cibs.db.dao.sysmngmt.NodeDaoMySqlImpl.getAllNodes(NodeDaoMySqlImpl.java:51)
20:00:08,124 ERROR [stderr] (DefaultQuartzScheduler_Worker-1)   at com.comsats.cibs.db.dao.sysmngmt.SysMngmntFacade.getAllNodes(SysMngmntFacade.java:874)
20:00:08,124 ERROR [stderr] (DefaultQuartzScheduler_Worker-1)   at com.comsats.cibs.schedular.InvoiceGeneration.execute(InvoiceGeneration.java:31)
20:00:08,124 ERROR [stderr] (DefaultQuartzScheduler_Worker-1)   at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
20:00:08,124 ERROR [stderr] (DefaultQuartzScheduler_Worker-1)   at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)



What I have tried:

I am running a schedular in which i m making a call to the database:

@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
    synchronized(String.class){
        CIBSInvoiceGenerationTimer ci = new CIBSInvoiceGenerationTimer();
        InvoiceTransationManager it = new InvoiceTransationManager();
        Iterator nodes = null;
        SysMngmntFacade sysFacade = SysMngmntFacade.getInstance();

        try {
            nodes = sysFacade.getAllNodes();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (NoRecordsFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } 
    }
}



getAllNodes goes to connect to the db like:

CIBSPoolManager poolManager = CIBSPoolManager.getInstance();
 Connection connect = poolManager.getConnection("mysql");



than in getConnection:


public Connection getConnection(String name) {

    conn = pool.getConnection(); 
    return conn;
}



then in pool.getConnection

public Connection getConnection()
{
    InitialContext initContext = null;
    Context envContext = null;
    DataSource ds=null;
    Connection conn=null;
    try {
        initContext = new InitialContext();
    } catch (NamingException e3) {
        // TODO Auto-generated catch block
        e3.printStackTrace();
    }

    try {
        envContext = (Context)initContext.lookup("java:comp/env");
    } catch (NamingException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }

    try {
        ds = (DataSource) envContext.lookup("cibsmysql");
    } catch (NamingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    try {
        conn = ds.getConnection();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("Connection acquired");
    return conn;
}



I have used this code everywhere in the project and it has worked fine . But now i wanted to make a schedular to run some code but in schedular when i come to the line :

envContext = (Context)initContext.lookup("java:comp/env");



Can someone please guide me . It's pretty obvious that the reason of not connecting probably because of this schedular but i can't figure out the reason and solution. I have asked on other forum too but no answer . Need help :(

解决方案

WorkerThread.run(SimpleThreadPool.java:573)



What I have tried:

I am running a schedular in which i m making a call to the database:

@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
    synchronized(String.class){
        CIBSInvoiceGenerationTimer ci = new CIBSInvoiceGenerationTimer();
        InvoiceTransationManager it = new InvoiceTransationManager();
        Iterator nodes = null;
        SysMngmntFacade sysFacade = SysMngmntFacade.getInstance();

        try {
            nodes = sysFacade.getAllNodes();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (NoRecordsFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } 
    }
}



getAllNodes goes to connect to the db like:

CIBSPoolManager poolManager = CIBSPoolManager.getInstance();
 Connection connect = poolManager.getConnection("mysql");



than in getConnection:


public Connection getConnection(String name) {

    conn = pool.getConnection(); 
    return conn;
}



then in pool.getConnection

public Connection getConnection()
{
    InitialContext initContext = null;
    Context envContext = null;
    DataSource ds=null;
    Connection conn=null;
    try {
        initContext = new InitialContext();
    } catch (NamingException e3) {
        // TODO Auto-generated catch block
        e3.printStackTrace();
    }

    try {
        envContext = (Context)initContext.lookup("java:comp/env");
    } catch (NamingException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }

    try {
        ds = (DataSource) envContext.lookup("cibsmysql");
    } catch (NamingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    try {
        conn = ds.getConnection();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("Connection acquired");
    return conn;
}



I have used this code everywhere in the project and it has worked fine . But now i wanted to make a schedular to run some code but in schedular when i come to the line :

envContext = (Context)initContext.lookup("java:comp/env");



Can someone please guide me . It's pretty obvious that the reason of not connecting probably because of this schedular but i can't figure out the reason and solution. I have asked on other forum too but no answer . Need help :(


这篇关于Javax.naming.namenotfoundexcep ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆