Name [name] is not bound in this Context. Unable to find [jdbc]

0

In the hope of improving access performance in DB, I started to implement a pool of connections within my Web Application. But whenever I go to give a lookup in the application I get the following error

  

javax.naming.NameNotFoundException: Name [jdbc / bag] is not bound in this Context. Unable to find [jdbc].       at org.apache.naming.NamingContext.lookup (NamingContext.java:818)       at org.apache.naming.NamingContext.lookup (NamingContext.java:166)       at org.apache.naming.SelectorContext.lookup (SelectorContext.java:157)       at javax.naming.InitialContext.lookup (InitialContext.java:417)       at Filter.Filter filter (Filter.java:52)       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:239)       at org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:206       .... (continued)

Looking for multiple QeA and tutorials I ended up implementing the Tomcat files as follows

server.xml

<GlobalNamingResources>
    <Resource name="jdbc/bolsa" auth="Container" type="javax.sql.DataSource"
      maxTotal="100" maxIdle="30" maxWaitMillis="10000"
      username="root" password="" driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://localhost:3306/bolsa"/>
</GlobalNamingResources>

context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/zk_login">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

    <ResourceLink global="jdbc/bolsa" name="jdbc/bolsa" type="javax.sql.DataSource" />

    <Resource name="jdbc/bolsa" auth="Container" type="javax.sql.DataSource"
              maxTotal="100" maxIdle="30" maxWaitMillis="10000"
              username="root" password="" driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/bolsa"/>
</Context>

Inside my sistema I

asked by anonymous 28.09.2017 / 18:12

1 answer

0

I solved my problem and had to solve several other problems together. So I'll show you the solution all step by step.

Hibernate version change

I was using the hibernate-core-4.3.0 and hibernate-entitymanager-4.3.0 version. But as my goal was to use Connection Pool, I had to upgrade the version of hibernate since these had problems implementing Data Source.

So I switched to the hibernate-core-5.2.11 and hibernate-entitymanager-5.2.11 version. With this, some commands have been modified. The ejb library has become decrepated (outdated) from version 4.3, so you have to use the jpa library as seen in that post

Provider also changed and moved from HibernatePersistence to HibernatePersistenceProvider .

So% w / w% was as follows:

<persistence-unit name="bolsa" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <non-jta-data-source>java:comp/env/jdbc/bolsa</non-jta-data-source>
    ...
</persistence-unit>

Connection pool (DataSource) using Tomcat

Although I modified a lot of persistence.xml , the only thing I needed was Tomcat , which was:

<?xml version="1.0" encoding="UTF-8"?>
<Context >
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

    <!-- <ResourceLink global="jdbc/bolsa" name="jdbc/bolsa" type="javax.sql.DataSource" /> -->

    <Resource name="jdbc/bolsa" auth="Container" type="javax.sql.DataSource"
              maxTotal="100" maxIdle="30" maxWaitMillis="10000"
              username="root" password="" driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/bolsa"/>
</Context>

With this I can capture the Data source through the command:

<non-jta-data-source>java:comp/env/jdbc/bolsa</non-jta-data-source>

Just remember to put context.xml before the DataSource file.

    
19.10.2017 / 22:49