“
Problema
Quando o serviço Tomcat, usado pela Aplicação Oobj, é iniciado e o mesmo não possui configurado a conexão com o Banco de Dados é mostrado o erro abaixo nos logs do serviço:
[localhost-startStop-1] 0906 08:38:03,927 INFO NamingHelper - JNDI InitialContext properties:{} [localhost-startStop-1] 0906 08:38:03,928 ERROR ceConnectionProvider - Could not find datasource: java:comp/env/jdbc/oobjCentralDs javax.naming.NameNotFoundException: Name [jdbc/oobjCentralDs] is not bound in this Context. Unable to find [jdbc]. at org.apache.naming.NamingContext.lookup(NamingContext.java:819) at org.apache.naming.NamingContext.lookup(NamingContext.java:167) at org.apache.naming.factory.ResourceLinkFactory.getObjectInstance(ResourceLinkFactory.java:97) at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source) at org.apache.naming.NamingContext.lookup(NamingContext.java:842) at org.apache.naming.NamingContext.lookup(NamingContext.java:153) at org.apache.naming.NamingContext.lookup(NamingContext.java:830) at org.apache.naming.NamingContext.lookup(NamingContext.java:153) at org.apache.naming.NamingContext.lookup(NamingContext.java:830) at org.apache.naming.NamingContext.lookup(NamingContext.java:153) at org.apache.naming.NamingContext.lookup(NamingContext.java:830) at org.apache.naming.NamingContext.lookup(NamingContext.java:167) at org.apache.naming.SelectorContext.lookup(SelectorContext.java:156) at javax.naming.InitialContext.lookup(Unknown Source) at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75) at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137) at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325) at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34) at org.utils.core.dao.jpa.jse.JpaDaoImplJse.createEntityManagerFactory(JpaDaoImplJse.java:59) at org.utils.core.dao.jpa.jse.support.EntityManagerFactoryListener.contextInitialized(EntityManagerFactoryListener.java:36) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1259) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1998) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
Normalmente, esse problema ocorre quando há reinstalação do Tomcat, e algumas configurações são perdidas.
Solução/Procedimento
Para corrigir esse problema deverá ser editado o arquivo server.xml salvo no caminho (padrão) >> C:\Oobj\Aplicativos\Tomcat7\conf\server.xml. Para isso, abra o arquivo com um editor de texto (recomendamos o NotePad++).
Siga os passos para corrigir o problema:
1 – Localize seguinte o trecho dentro do arquivo server.xml:
<Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" />
A depender do Banco de Dados usado, a string de conexão pode mudar um pouco. Veja abaixo um exemplo para cada um dos Bancos de Dados que são compatíveis com a Aplicação Oobj.
2 – Inseria a string de conexão de acordo com o seu Banco de Dados:
-
Para Banco de Dados PostgreSQL:
<Resource acquireIncrement="5" acquireRetryAttempts="30" acquireRetryDelay="1000" auth="Container" driverClass="org.postgresql.Driver" factory="org.apache.naming.factory.BeanFactory" jdbcUrl="jdbc:postgresql://127.0.0.1/oobj_nfe_central" maxIdleTime="240" maxPoolSize="20" minPoolSize="5" name="jdbc/oobjCentralDs" password="oobj.postgres" type="com.mchange.v2.c3p0.ComboPooledDataSource" user="postgres"/>
-
Para Banco de Dados SQL Server:
<Resource acquireIncrement="5" acquireRetryAttempts="30" acquireRetryDelay="1000" auth="Container" driverClass="net.sourceforge.jtds.jdbc.Driver" factory="org.apache.naming.factory.BeanFactory" jdbcUrl="jdbc:jtds:sqlserver://10.102.20.126:1433/NFE" maxIdleTime="240" maxPoolSize="20" minPoolSize="5" name="jdbc/oobjCentralDs" password="su_nfe" type="com.mchange.v2.c3p0.ComboPooledDataSource" user="u_nfe"/>
-
Para Banco de Dados Oracle:
<Resource acquireIncrement="5" acquireRetryAttempts="30" acquireRetryDelay="1000" auth="Container" driverClass="oracle.jdbc.driver.OracleDriver" factory="org.apache.naming.factory.BeanFactory" jdbcUrl="jdbc:oracle:thin:@//192.168.0.121:1521/orcl" maxIdleTime="240" maxPoolSize="150" minPoolSize="5" name="jdbc/oobjCentralDs" password="teste" type="com.mchange.v2.c3p0.ComboPooledDataSource" user="teste"/>
3 – Após adicionar a string de conexão com o banco de dados, deverá ficar como no exemplo abaixo:
<GlobalNamingResources> <!-- Editable user database that can also be used by UserDatabaseRealm to authenticate users --> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> <!-- PostgreSQL --> <Resource acquireIncrement="3" acquireRetryAttempts="30" acquireRetryDelay="1000" auth="Container" driverClass="org.postgresql.Driver" factory="org.apache.naming.factory.BeanFactory" jdbcUrl="jdbc:postgresql://localhost:5432/oobj_nfe_central" maxIdleTime="240" maxPoolSize="100" minPoolSize="5" name="jdbc/oobjCentralDs" password="oobj.postgres" type="com.mchange.v2.c3p0.ComboPooledDataSource" user="postgres"/> </GlobalNamingResources>
4 – Salve o arquivo server.xml e reinicie o Serviço Apache Tomcat 7.
Referência
Sem referências.
“