ClassNotFoundException with Elastic Beanstalk and

2019-07-15 03:13发布

I am trying to deploy a maven-built Java web app to Elastic Beanstalk, which is running an environment under the Amazon Linux Tomcat 7 version. The app works fine on localhost, even with an external mysql database (XEROUND).

My original context.xml has a resource as follows:

<Resource auth="Container"        
    driverClassName="com.mysql.jdbc.Driver" 
    logAbandoned="true" 
    maxActive="100" 
    maxIdle="30" 
    maxWait="10000" 
    name="jdbc/xxxx-01292013" 
    password="xxxx" 
    removeAbandoned="true" 
    removeAbandonedTimeout="60" 
    type="javax.sql.DataSource" 
    url="jdbc:mysql://instancexxxx.db.xeround.com:xxxx/xxxx-01292013?   autoReconnect=true"
    username="xxxx-general"/>

However, when I run this app, I get the following error:

java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory

I tried adding the following lines to my context.xml resource:

factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"

but that didn't work either. I then tried adding this line:

factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"

but that gives me the new exception:

javax.naming.NamingException: com.mysql.jdbc.Driver

I am pounding my head against a wall here, does anyone know what I can do to get this thing up and running?

1条回答
老娘就宠你
2楼-- · 2019-07-15 03:46

Okay, so after some more experimentation and playing around with configurations, I have my app working by putting the following in my context.xml Resource tag:

    factory="org.apache.commons.dbcp.BasicDataSourceFactory"

and the following in my pom.xml file:

    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.4</version>
    </dependency>

    <dependency>
        <groupId>commons-pool</groupId>
        <artifactId>commons-pool</artifactId>
        <version>1.6</version>
    </dependency>

    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.1</version>
    </dependency>

This answer was given to me at the AWS Forums here.

However, the better solution that I will be trying to get to work is by putting an .ebextensions file in my app, writing a .config file for it, and getting it to work that way. I think that this approach will be better suited long-term, as it will allow me to address any further configuration mis-match issues between my dev environment and elastic beanstalk's Tomcat 7. This solution is also laid out at the AWS Forums here, and here.

查看更多
登录 后发表回答