AWS Elastic Beanstalk deploy failing - jdbc/CubaDS not bound in this Context

I am attempting to deploy a project on AWS using Elastic Beanstalk, but I cannot seem to get it to work.

The error I am getting is:

javax.naming.NameNotFoundException: Name [jdbc/CubaDS] is not bound in this Context. Unable to find [jdbc].

My buildWar is as follows:

task buildWar(type: CubaWarBuilding) {
    logbackConfigurationFile = 'etc/war-logback.xml'
    coreContextXmlPath = 'modules/core/web/META-INF/war-context.xml'
    webXmlPath = 'modules/web/web/WEB-INF/single-war-web.xml'
    appProperties = ['cuba.automaticDatabaseUpdate' : true
    ]
    includeContextXml = true
    includeJdbcDriver = true
    appHome = '/var/lib/tomcat8/webapps/ROOT'
    polymerBuildDir = 'bundled'
}

war-context.xml:

<Context>
    <!-- Database connection -->
    <Resource driverClassName="org.postgresql.Driver"
              maxIdle="2"
              maxTotal="20"
              maxWaitMillis="5000"
              name="jdbc/CubaDS"
              password="<password>"
              type="javax.sql.DataSource"
              url="jdbc:postgresql://<url>"
              username="<username>"/>
    <!-- Switch off session serialization -->
    <Manager pathname=""/>
</Context>

I’ve thought that perhaps the module prefix needs to be swapped from app to ROOT, so I tried that, but it didn’t work.
I tried to set appHome to /var/lib/tomcat8/webapps (without /ROOT), but the error stayed the same.
When I SSHed in to look around, I found that the PostgreSQL JAR does exist in /var/lib/tomcat8/webapps/ROOT/WEB-INF/lib/.

Where am I going wrong?

I am using platform-6.10.7.

EDIT:
Elastic Beanstalk’s configuration is as follows:

Tomcat 8.5 with Java 8 running on 64bit Amazon Linux/3.1.0

I am facing the same problem. I am using mysql with same rest of the configuration. Please help!

Hi,

Please check that WAR contains META-INF/context.xml file. сontext.xml must contain JDBC configuration from war-context.xml

Thanks @subbotin. Verified the things that you mentioned. All there.
Also, I am able to connect to AWS mysql instance from my local tomcat deployment with the same war that I am trying to deploy using AWS EBS.
But no luck on AWS EC2 instance tomcat. Anything else that I could be missing. Do I need a different mysql-java-connector for AWS EC2 instance than I am using locally?

Could you provide log file from AWS EC2 tomcat instance?

here you go. catalina.2019-02-05.log (47.4 KB)

Also here’s my buildWar task -

task buildWar(type: CubaWarBuilding) {
    appHome = '${catalina.base}/work'
    singleWar = true
    includeContextXml = true
    includeJdbcDriver = true
    appProperties = ['cuba.automaticDatabaseUpdate': true]
    webXmlPath = 'modules/web/web/WEB-INF/single-war-web.xml'
    coreContextXmlPath = 'modules/core/web/META-INF/prod-context.xml'
}

and my prod-context.xml

<Context>
    <!-- Database connection -->
    <Resource driverClassName="com.mysql.jdbc.Driver"
              maxIdle="2"
              maxTotal="20"
              maxWaitMillis="5000"
              name="jdbc/CubaDS"
              password="xxxxxx"
              type="javax.sql.DataSource"
              url="jdbc:mysql://xxxxx.rds.amazonaws.com:3306/omega?useSSL=false&amp;allowMultiQueries=true&amp;allowPublicKeyRetrieval=true"
              username="xxxxx"/>
    <!-- Switch off session serialization -->
    <Manager pathname=""/>
</Context>

I’ve found an error in the log file:
Failed to register in JMX: [javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory]]

Could you try to add factory attribute to prod-context.xml, rebuild WAR and deploy again.

<Context>
    <!-- Database connection -->
    <Resource driverClassName="com.mysql.jdbc.Driver"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
              maxIdle="2"
              maxTotal="20"
              maxWaitMillis="5000"
              name="jdbc/CubaDS"
              password="xxxxxx"
              type="javax.sql.DataSource"
              url="jdbc:mysql://xxxxx.rds.amazonaws.com:3306/omega?useSSL=false&amp;allowMultiQueries=true&amp;allowPublicKeyRetrieval=true"
              username="xxxxx"/>
    <!-- Switch off session serialization -->
    <Manager pathname=""/>
</Context>

If any error happens, please attach log to the topic.

2 Likes

That resolved the issue. Thank you so much @subbotin!!

Turns out that this was the same problem for me. Adding the factory attribute allowed me to move on to solving other issues with my deploy.
Thanks a lot @subbotin!

Why this line is not generated by the cuba studio?

It’s a Tomcat specific problem in a AWS Elastic Beanstalk, and doesn’t relate to the CUBA and CUBA Studio.

1 Like

Hello i have the same error when i try to deploy to aws, its weird but it works on my loCal server