0

我不断收到此错误,并尝试了许多网上传闻的修复方法,但均无济于事。

这是一个例外:

javax.naming.NameNotFoundException: Name java:comp is not bound in this Context
    at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at my.app.database.DatabaseManager.connect(DatabaseManager.java:44)
    at my.app.database.DatabaseManager.return(DatabaseManager.java:133)
    at my.app.GenParse.GeneratePastPositions.updateSatHistory(GeneratePastPositions.java:89)
    at my.app.updateHistory.run(SatelliteEclipseServer.java:72)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

我的资源声明context.xml如下:

<?xml version='1.0' encoding='utf-8'?>

<!-- The contents of this file will be loaded for each web application -->
<Context reloadable="true">

    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>

    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->

    <!-- Uncomment this to enable Comet connection tacking (provides events
         on session expiration as well as webapp lifecycle) -->
    <!--
    <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
    -->
     <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
               username="myUsername" password="myPassword" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://mysql.myServer.com:3306/myUserName"/>


</Context>

我的java代码中的连接:

public void connect() throws SQLException, NamingException{
    initCtx = new InitialContext();
    envCtx = (Context) initCtx.lookup("java:comp/env");
    ds = (DataSource) envCtx.lookup("jdbc/TestDB");         
} 

我认为也正因为如此,它没有像应有的那样关闭连接。除了错误消息之外,它都可以正常工作,但我认为这个错误会随着时间的推移而复杂化并耗尽所有可用的连接。

我真的很感激这方面的一些帮助,因为它让我烦恼了好几个星期!

4

0 回答 0