0
In the expectation of improving the performance of BD access I started to implement a pool of connections within my Web Application. But every time I will give a lookup on the application I think the following error occurs
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.Filtro.doFilter(Filter.java:52) at org.apache.Catalina.core.Applicationfilterchain.internalDoFilter(Applicationfilterchain.java:239) at org.apache.Catalina.core.Applicationfilterchain.doFilter(Applicationfilterchain.java:206 .... (continue)
When searching several Qea and tutorials I ended up implementing the files of Tomcat as follows
xml server.
<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>
xml context.
<?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>
Already inside of mine sistema I the persistence.xml was as follows
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="bolsa" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <non-jta-data-source>java:comp/env/jdbc/bolsa</non-jta-data-source>
        <class>bean.Permissao</class>
        <class>bean.Usuario</class>
        <class>bean.Pagina</class>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
            <property name="hibernate.show_sql" value="true"/>
            <!-- dados da conexao -->
            <!--  propriedades do hibernate -->
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
            <property name="hibernate.format_sql" value="true"/>
        </properties>
    </persistence-unit>
</persistence>
and the web xml.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">
    <description>MySQL Test App</description>
    <resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/bolsa</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
</web-app>
How can I set up my server or if my call is wrong and how can I fix this problem.
Unfortunately I’ve looked at several tutorials and video but none of it worked :/
If you take the tag
<Resource ..... />context.xml does not work?– igventurelli
Unfortunately the same mistake happens.
– Victor Henrique