Skip to Content
0
Apr 06, 2020 at 02:04 PM

Tomcat without global resource

503 Views

Hello

I am getting this error when I startup SAP Commerce 1811 (with JNDI and Oracle DB) locally:

SCHWERWIEGEND: Exception sending context initialized event to listener instance of class [de.hybris.platform.spring.HybrisContextLoaderListener]
java.lang.RuntimeException: java.sql.SQLException: error looking up JNDI data source 'java:comp/env/jdbc/hybrisDS' due to Name [comp/env/jdbc/hybrisDS] is not bound in this Context. Unable to find [comp].
        at de.hybris.platform.jdbcwrapper.DataSourceImpl.adjustDatabaseInfos(DataSourceImpl.java:660)
        at de.hybris.platform.jdbcwrapper.DataSourceImpl.<init>(DataSourceImpl.java:218)
        at de.hybris.platform.jdbcwrapper.DataSourceImpl.<init>(DataSourceImpl.java:168)

My customer requires to not have a global resource defined in server.xml. Therefore I moved the resource definition to the context.xml. Here are the 2 files + ammendment tot the web.xml in my storefront:
server.xml

<Server port="-1" shutdown="SHUTDOWN">
<Listener className="de.hybris.tomcat.HybrisGlobalResourcesLifecycleListener"  dataSourceName="java:comp/env/jdbc/hybrisDS"/>
  <GlobalNamingResources></GlobalNamingResources>
  <Service name="Catalina" >
	<Executor     name="hybrisExecutor"
			        namePrefix="hybrisHTTP"
			        maxThreads="200"
			        minSpareThreads="40"
			        maxIdleTime="10000"/>
    <Connector port="9001"
			   maxHttpHeaderSize="8192"
			   maxPostSize="6291456"
               maxThreads="200"
               protocol="HTTP/1.1"
               executor="hybrisExecutor"
               enableLookups="false"
               acceptCount="100"
               connectionTimeout="20000"
               URIEncoding="UTF-8"
               disableUploadTimeout="true" />
    <Connector port="9002"
			   maxHttpHeaderSize="8192"
			   maxPostSize="6291456"
               maxThreads="150"
               protocol="HTTP/1.1"
               executor="hybrisExecutor"
               enableLookups="false"
               acceptCount="100"
               connectionTimeout="20000"
               disableUploadTimeout="true"
               URIEncoding="UTF-8"
               SSLEnabled="true"
					scheme="https"
					secure="true"
					clientAuth="false"
   				sslProtocol = "TLS"
   				keyAlias="1"
   				keystoreFile="${catalina.home}/lib/keystore"
   				keystorePass="123456"
                />
	<Connector  protocol="AJP/1.3"  URIEncoding="UTF-8"  port="8009" />	
    <Engine name="Catalina" defaultHost="localhost" startStopThreads="0">
			<Valve 	className="org.apache.catalina.valves.AccessLogValve"
             		directory="D:\Projekte\myproject\hybris\log/tomcat"
	      		 	prefix="access."
        	   		suffix=".log"
	      		 	pattern="combined"
          />
      <Host 	name="localhost"
      			appBase="webapps"
		       	unpackWARs="false"
		       	autoDeploy="false"
		       	startStopThreads="0">		       	
		        <Valve className="org.apache.catalina.valves.ErrorReportValve" 
		               showReport="false" 
		               showServerInfo="false"/>
.....
			<!-- 'hac' extension's context for tenant 'master' -->
			<Context path="/hac" docBase="D:\Projekte\myproject\hybris\bin\platform\ext\hac/web/webroot" >
				<Manager pathname="" />
				<Loader platformHome="D:\Projekte\myproject\hybris\bin\platform" className="de.hybris.tomcat.HybrisWebappLoader" deployName="default" />
				
				<JarScanner >
					<JarScanFilter defaultTldScan="false" tldScan="${tomcat.util.scan.StandardJarScanFilter.jarsToScan},taglibs-standard-impl*.jar,spring-security-taglibs-*.jar,spring-webmvc*.jar,displaytag*.jar,javax.servlet.jsp.jstl-*.jar" defaultPluggabilityScan="false" pluggabilityScan="${tomcat.util.scan.StandardJarScanFilter.jarsToScan},taglibs-standard-impl*.jar,spring-security-taglibs-*.jar,spring-webmvc*.jar,displaytag*.jar,javax.servlet.jsp.jstl-*.jar,*_hac.jar" />
				</JarScanner>
			</Context>
.....
			<!-- 'backoffice' extension's context for tenant 'master' -->
			<Context path="/backoffice" docBase="D:\Projekte\myproject\hybris\bin\ext-backoffice\backoffice/web/webroot" >
				<Manager pathname="" />
				<Loader platformHome="D:\Projekte\myproject\hybris\bin\platform" className="de.hybris.tomcat.HybrisWebappLoader" deployName="default" />
				
				<JarScanner >
					<JarScanFilter defaultTldScan="false" tldScan="${tomcat.util.scan.StandardJarScanFilter.jarsToScan},taglibs-standard-impl*.jar,spring-security-taglibs-*.jar,spring-webmvc*.jar" defaultPluggabilityScan="false" pluggabilityScan="${tomcat.util.scan.StandardJarScanFilter.jarsToScan},taglibs-standard-impl*.jar,spring-security-taglibs-*.jar,spring-webmvc*.jar,webfragment*.jar" />
				</JarScanner>
			</Context>
.....
			<!-- 'myShop' extension's context for tenant 'master' -->
			<Context path="/myShop" docBase="D:\Projekte\myproject\hybris\bin\ext-storefront\myShop/web/webroot" useHttpOnly="true">
				<Manager pathname="" />
				<Loader platformHome="D:\Projekte\myproject\hybris\bin\platform" className="de.hybris.tomcat.HybrisWebappLoader" deployName="default" />
				
				<JarScanner >
					<JarScanFilter defaultTldScan="false" tldScan="${tomcat.util.scan.StandardJarScanFilter.jarsToScan},taglibs-standard-impl*.jar,spring-security-taglibs-*.jar,spring-webmvc*.jar,json-taglib*.jar,jstl-impl*.jar" defaultPluggabilityScan="false" pluggabilityScan="${tomcat.util.scan.StandardJarScanFilter.jarsToScan},taglibs-standard-impl*.jar,spring-security-taglibs-*.jar,spring-webmvc*.jar,json-taglib*.jar,jstl-impl*.jar" />
				</JarScanner>
			</Context>
      </Host>
    </Engine>
  </Service>
</Server>
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/app/NTQ" sessionCookiePath="/app/NTQ"
         docBase="D:\Projekte\myProject\hybris\bin\platform\..\ext-storefront\myShop\web\webroot"
         privileged="true" antiResourceLocking="false" unpackWAR="false" >

    <Manager pathName="" className="org.apache.catalina.session.StandardManager"/>
    <Loader platformHome="D:\Projekte\myProject\hybris\bin\platform" className="de.hybris.tomcat.HybrisWebappLoader" deployName="default" />
    <Resource name="jdbc/hybrisDS"
              auth="Container"
              type="oracle.jdbc.pool.OracleDataSource"
              username="hybris"
              password="hybris"
              driverClassName="oracle.jdbc.driver.OracleDriver"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
              maxActive="90"
              maxIdle="90"
              maxWait="10000"
              testWhileIdle="true"
              timeBetweenEvictionRunsMillis="10000"
              minEvictableIdleTimeMillis="300000"
              numTestsPerEvictionRun="100"
              testOnBorrow="true"
              testOnReturn="true"
              whenExhaustedAction="1"
              url="jdbc:oracle:thin:@localhost:1521:xe"
    />
</Context>

web.xml (added resource registry):

<resource-ref>
   <description>This is a reference to the global Resource for MySQL database connetion.</description>
   <res-ref-name>jdbc/hybrisDS</res-ref-name>
   <res-type>oracle.jdbc.pool.OracleDataSource</res-type>
   <res-auth>Container</res-auth>
</resource-ref>

local.properties (db properties)

db.pool.name=hybrisDS
db.pool.fromJNDI=java:comp/env/jdbc/${db.pool.name}
db.pool.fromJNDI.dbtype=oracle

Am I missing here some configuration?

Regards

Andy