Tomcat 5.5 Erro: Null component Catalina:type=DataSource

Bom dia.

Estou com um problema ao startar o Tomcat 5.5. O erro é o seguinte:

SEVERE: Null component Catalina:type=DataSource,path=/gepla,host=localhost,class=javax.sql.DataSource,name=“jdbc/gepla”

Dei uma olhada na Net, no site da Apache, segui as configurações lá pedidas, porém sem sucesso…

Se alguém puder me ajudar, agradeço desde já!

:wink:

Arquivos relacionados:

Meu contexto (localizado na pasta: C:\Tomcat 5.5\conf\Catalina\localhost\gepla.xml):

<Context path="/gepla" reloadable="true" docBase="C:\eclipse\workspace\gepla" workDir="C:\eclipse\workspace\gepla\work" debug="5" crossContext="true">
	<Resource name="jdbc/gepla" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://172.18.3.229:3306/gepla" username="root" 
	password="root" maxActive="20" maxIdle="10" maxWait="-1"/>
	<Resource name="jdbc/gca" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://172.18.3.229:3306/gca" username="root" 
	password="root" maxActive="20" maxIdle="10" maxWait="-1"/>
</Context>

Meu web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- ainda nao sei pra serve essa parte
<!DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
  "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
-->

<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"> 
     
  <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/gepla</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>
 <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/gca</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>




  <display-name>Struts Blank Application</display-name>

  <!-- Standard Action Servlet Configuration (with debugging) -->
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>2</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>


  <!-- Standard Action Servlet Mapping -->
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>


  <!-- The Usual Welcome File List -->
  <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
  </welcome-file-list>

  <!-- Struts Tag Library Descriptors -->
  <taglib>
    <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
  </taglib>


  <!-- struts-el -->

  <taglib>
    <taglib-uri>/WEB-INF/struts-bean-el.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-bean-el.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/struts-html-el.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-html-el.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/struts-logic-el.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-logic-el.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/struts-tiles-el.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-tiles-el.tld</taglib-location>
  </taglib>

  <!-- struts-el -->




  <taglib>
    <taglib-uri>formata</taglib-uri>
    <taglib-location>/WEB-INF/formata.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>/WEB-INF/tld/paginacao</taglib-uri>
    <taglib-location>/WEB-INF/paginacao.tld</taglib-location>
  </taglib>




  <!-- Struts Tag Library Descriptors -->
	<taglib>
		<taglib-uri>/WEB-INF/tld/c.tld</taglib-uri>
		<taglib-location>/WEB-INF/tld/c-1_0-rt.tld</taglib-location>
	</taglib>
	<taglib>
		<taglib-uri>/WEB-INF/tld/fmt</taglib-uri>
		<taglib-location>/WEB-INF/tld/fmt-1_0-rt.tld</taglib-location>
	</taglib>



</web-app>

Minha classe de conexao:

package br.com.gepla.conexao;

import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;


import java.sql.SQLException;
import java.sql.SQLException;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;


import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.Map;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class Conexao implements Connection  {

	protected static DataSource dataSource;

	Connection conn = null;

	public Conexao() throws Exception {
		if (dataSource == null) {
			try {
				InitialContext ic = new InitialContext();
				// tomcat mysql
				// dataSource = (DataSource)
				// ic.lookup("java:comp/env/jdbc/StrutsDemoDS");

				// tomcat sql server
				dataSource = (DataSource) ic.lookup("java:comp/env/jdbc/gepla");

				// JBoss
				// dataSource = (DataSource)
				// ic.lookup("java:jdbc/StrutsDemoDS");

			} catch (NamingException ex) {
				System.out.println(ex.getMessage());
				throw ex;
			}
		}
	}

	public Connection getConnection() throws SQLException {
		try {
			conn = dataSource.getConnection();
		} catch (SQLException e) {
			throw e;
		}
		return conn;
	}

	public void closeConnection(PreparedStatement stmt, ResultSet rs)
			throws SQLException {

		if (rs != null) {
			try {
				rs.close();
				rs = null;
			} catch (SQLException e) {
			}
		}
		if (stmt != null) {
			try {
				stmt.close();
				stmt = null;
			} catch (SQLException e) {
			}
		}
		fechaConexao();

	}

	public void fechaConexao() throws SQLException {
		if (conn != null)
			conn.close();

	}

	public void clearWarnings() throws SQLException {
		// TODO Auto-generated method stub

	}

	public void close() throws SQLException {
		// TODO Auto-generated method stub

	}

	public void commit() throws SQLException {
		// TODO Auto-generated method stub

	}

	public Statement createStatement() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean getAutoCommit() throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	public String getCatalog() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public int getHoldability() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public DatabaseMetaData getMetaData() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public int getTransactionIsolation() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public Map getTypeMap() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public SQLWarning getWarnings() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean isClosed() throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean isReadOnly() throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	public String nativeSQL(String sql) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public CallableStatement prepareCall(String sql) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public PreparedStatement prepareStatement(String sql) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public void releaseSavepoint(Savepoint savepoint) throws SQLException {
		// TODO Auto-generated method stub

	}

	public void rollback() throws SQLException {
		// TODO Auto-generated method stub

	}

	public void rollback(Savepoint savepoint) throws SQLException {
		// TODO Auto-generated method stub

	}

	public void setAutoCommit(boolean autoCommit) throws SQLException {
		// TODO Auto-generated method stub

	}

	public void setCatalog(String catalog) throws SQLException {
		// TODO Auto-generated method stub

	}

	public void setHoldability(int holdability) throws SQLException {
		// TODO Auto-generated method stub

	}

	public void setReadOnly(boolean readOnly) throws SQLException {
		// TODO Auto-generated method stub

	}

	public Savepoint setSavepoint() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public Savepoint setSavepoint(String name) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public void setTransactionIsolation(int level) throws SQLException {
		// TODO Auto-generated method stub

	}


	 public void setClientInfo(Properties properties) {
			// TODO Auto-generated method stub

		}

	public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public Blob createBlob() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public Clob createClob() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}




	public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public Properties getClientInfo() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public String getClientInfo(String name) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean isValid(int timeout) throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}



	

	public void setTypeMap(Map map) throws SQLException {
		// TODO Auto-generated method stub
		
	}



	public Object unwrap(Class arg0) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean isWrapperFor(Class arg0) throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}





}

caro colega se não me engano para configurar pool do tomcat 5.5 somente e necessário que se mexa no context.xml que fica dentro de META-INF/context.xml da aplicação de acordo com a especificação do site oficial:

http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html

e quanto a essas configurações e o seguinte no tomcat 5.5 e de uma forma no 4.1 e outra então deve ser essas diferenças entre versões que não e tão difundida que deve ter feito essa confusão em sua cabeça tive esse problema quebrei a cabeça uma semana mais consegui configurar tanto no 4.1 quanto no 5.5 qualquer coisa posta ai espero ter ajudado

[quote=gerdec]caro colega se não me engano para configurar pool do tomcat 5.5 somente e necessário que se mexa no context.xml que fica dentro de META-INF/context.xml da aplicação de acordo com a especificação do site oficial:

http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html

e quanto a essas configurações e o seguinte no tomcat 5.5 e de uma forma no 4.1 e outra então deve ser essas diferenças entre versões que não e tão difundida que deve ter feito essa confusão em sua cabeça tive esse problema quebrei a cabeça uma semana mais consegui configurar tanto no 4.1 quanto no 5.5 qualquer coisa posta ai espero ter ajudado[/quote]

É cara colega! :wink:

Bem, na verdade a configuração de contexto pode ser feita diretamente no server.xml, no context.xml do Tomcat ou no META-INF/context.xml, pelo menos foi o que entendi…

A Aplicação está subindo com o contexto no localhost e com o nome da aplicação, o rpoblema é que ela não está conectando ao banco de dados, pois está dando este erro de DataSource:
Null component Catalina:type=DataSource,path=/gepla,host=localhost,class=javax.sql.DataSource,name=“jdbc/gepla”

Tentei tirar o contexto e colocá-lo no context.xml, e no server.xml, porém continuo com o mesmo problema!

Então qualquer ajuda será bem vinda!!!

Obrigada

:wink:

Nossa, essa está difícil…

A tarde inteira quebrando cabeça e nada…

Ninguém aki usa o Tomcat 5.5? rs…

:wink:

Boa tarde, primeiramente quero me desculpar pelo caro colega e que estava com pressa e não prestei atenção e o seguinte observei seu código com mais atenção e percebi um erro o nome do datasource e esta errado e por isso ele resulta como null pois vc usa o contexto gepla na primeira configuração e na segunda gca


 <Resource name="jdbc/gepla" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://172.18.3.229:3306/gepla" username="root"   
     password="root" maxActive="20" maxIdle="10" maxWait="-1"/>  
     <Resource name="jdbc/gca" auth="Container" type="javax.sql.DataSource"

deve ser assim:

 <Resource name="jdbc/gepla" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://172.18.3.229:3306/gepla" username="root"   
     password="root" maxActive="20" maxIdle="10" maxWait="-1"/>  
     <Resource name="jdbc/gepla" auth="Container" type="javax.sql.DataSource"

espero ter ajudado e até apróxima Cara colega qualquer coisa posta ai tentaremos resolver

[quote=gerdec]Boa tarde, primeiramente quero me desculpar pelo caro colega e que estava com pressa e não prestei atenção e o seguinte observei seu código com mais atenção e percebi um erro o nome do datasource e esta errado e por isso ele resulta como null pois vc usa o contexto gepla na primeira configuração e na segunda gca


 <Resource name="jdbc/gepla" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://172.18.3.229:3306/gepla" username="root"   
     password="root" maxActive="20" maxIdle="10" maxWait="-1"/>  
     <Resource name="jdbc/gca" auth="Container" type="javax.sql.DataSource"

deve ser assim:

 <Resource name="jdbc/gepla" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://172.18.3.229:3306/gepla" username="root"   
     password="root" maxActive="20" maxIdle="10" maxWait="-1"/>  
     <Resource name="jdbc/gepla" auth="Container" type="javax.sql.DataSource"

espero ter ajudado e até apróxima Cara colega qualquer coisa posta ai tentaremos resolver[/quote]

Bom dia,

Não está errado… são dois bancos diferentes… mas estou tentando subir o código apenas com o datasource para o gepla.

Resumindo, não é esse o problema…

Obrigada pela atenção e continuo quebrando cabeça…

:wink: