常量java:comp没有绑定在这个上下文中的错误tomcat6

时间:2013-02-26 01:59:14

标签: java tomcat jdbc

我一直收到这个错误,并尝试了一些在线传闻的修复无济于事。

以下是例外:

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");         
} 

我认为也是因为它没有关闭它应该的连接。除了错误消息之外它的全部工作,但我认为这个错误会随着时间的推移而复杂化,并且会耗尽所有可用的连接。

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

0 个答案:

没有答案