BeanCreationException: Error creating bean with name 'cubaDataSource'

Hi community,

I try to do this example:


for my small application.

The chapter: 3. Configure CUBA to be delivered as a single war
show, how I can deploy this app into cloud. To do so, I have to copy this file:

After that, I build the war file and try to push to cloud.
But it fails with this problem:

    2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT Caused by: javax.naming.NameNotFoundException: Name [jdbc/CubaDS] is not bound in this Context. Unable to find [jdbc].
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     at org.apache.naming.NamingContext.lookup(NamingContext.java:816) ~[catalina.jar:8.5.24]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     at org.apache.naming.NamingContext.lookup(NamingContext.java:173) ~[catalina.jar:8.5.24]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     at org.apache.naming.SelectorContext.lookup(SelectorContext.java:163) ~[catalina.jar:8.5.24]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     at javax.naming.InitialContext.lookup(InitialContext.java:417) ~[na:1.8.0_162]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:106) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     at com.haulmont.cuba.core.sys.CubaJndiDataSourceFactoryBean.lookupWithFallback(CubaJndiDataSourceFactoryBean.java:27) ~[cuba-core-6.7.6.jar:6.7.6]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT     ... 48 common frames omitted
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT [CONTAINER] lina.core.ContainerBase.[Catalina].[localhost].[/] SEVERE  Exception sending context initialized event to listener instance of class [com.haulmont.cuba.core.sys.singleapp.SingleAppCoreServletListener]
       2018-03-26T15:19:40.58+0200 [APP/PROC/WEB/0] OUT org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [cuba-spring.xml]: Cannot resolve reference to bean 'cubaDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cubaDataSource' defined in class path resource [cuba-spring.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jdbc/CubaDS] is not bound in this Context. Unable to find [jdbc]. 

Does anyone have an hint for me, how to solve it @tsarev ? Thank you

Hi,
The exception means that JDBC driver is missed in the cloud environment. Try to add includeJdbcDriver = true to the buildWAR task. Or manually put it to the lib directory of the servlet container.

buildWar(type: CubaWarBuilding)  {
    webXmlPath = 'modules/web/web/WEB-INF/single-war-web.xml'
    appProperties = ['cuba.automaticDatabaseUpdate' : true]
    includeContextXml = true
    includeJdbcDriver = true
    appHome = 'app_home'
}

Thanks, how do you know that? Because I spend many hours on it, and could not know it…I am also new in this topic…