javax.naming.NameNotFoundException: Name [comp/env] is not bound in this Context. Unable to find [comp] error with java scheduler

后端 未结 6 1891
后悔当初
后悔当初 2021-02-05 23:02

What I\'m trying to do is to update my database after a period of time. So I\'m using java scheduler and connection pooling. I don\'t know why but my code only working once. It

相关标签:
6条回答
  • 2021-02-05 23:20

    This error shows that your jdbc resource is not registered! Where did you put your context.xml?

    The context.xml file must be in the META-INF directory of the war file. It must not be in the classes directory or in a jar file.

    Put the META-INF directory with the context.xml in the directory containing the root of the webapp in your source folder tree.

    0 讨论(0)
  • 2021-02-05 23:21

    I had the same problem which dragged on for two painful days. I Re-read tomcat documentation about JNDI, confirmed all my server.xml, context.xml,web.xml configuration and the code to access the naming object... still no progress.

    It turned out to be a dependency in my project that was interfering with the naming context - axis2. A simple move from axis2-1.6.0 to axis2-1.6.2 caused my problem.

    0 讨论(0)
  • 2021-02-05 23:27

    This problem is likely to arise when two versions of a same module are present. Kindly check the lib folder for multiple versions of the same module. Remove the version that you don't need and restart the server.

    In my case it was servlet-api present in two versions servlet-api.jar servlet-api-2.jar

    Hope this solves your problem. Good day!

    0 讨论(0)
  • 2021-02-05 23:33

    Try stopping and restarting your server (I assume you are using Eclipse and a Tomcat server). Maybe when you created your context xml file as it did was empty initially, your server was not able to synchronize its contents hence its inability to find the database connection resource name you later specified in the context.xml file.

    i.e. if you have not already solved this problem.

    0 讨论(0)
  • 2021-02-05 23:34

    It's not java:/comp/env but java:comp/env.

    0 讨论(0)
  • 2021-02-05 23:36

    I just ran in the same issue. In my case there was nothing wrong with my tomcat configuration files or my project but I had to restart my postgres service instance as my tomcat was running and it would somehow pick up the change and the exception disappeared. I had to restart windows for the problem to go away completely. No idea why!

    0 讨论(0)
提交回复
热议问题