aws / serverless-java-container

A Java wrapper to run Spring, Spring Boot, Jersey, and other apps inside AWS Lambda.
https://aws.amazon.com/serverless/
Apache License 2.0
1.5k stars 560 forks source link

Failed to configure a DataSource: 'url' attribute is not specified #353

Closed kawa9 closed 4 years ago

kawa9 commented 4 years ago

Scenario

I am Trying to setup a very simple example based on the Spring Boot 2 Quick Start (the ping example). My plan is to take the example and extend it by using a JPA Model (existing) to retrrieve data from a Aurora DB (also existing) and expose the data to REST. For developing I am using Eclipse with AWS Plugin to deploy to AWS (deploy serverless project).

Following steps I have so far executed: Generate Project with mvn archetype:generate as explained in the quick start (https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spring-Boot2) --> Works

change template.yml to serverless.template for being able to deploy with AWS Eclipse Plugin --> Works, indeed there is not much in there, it is only deploying a lambda and a API GW,

At this point everything is working fine, I can call the Ping URL and everything works as expected.

Next Step is the one where things stop working. Add these 2 dependencies to pom:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>LATEST</version>
            <scope>runtime</scope>
        </dependency>

Additionally I need to tell the lambda where the DB is. I am using Env variables for that, and I have a application.properties under the src/main/resources folder. I have added these lines there (only a logging entry was there).

## default connection pool
spring.datasource.hikari.connectionTimeout=20000
spring.datasource.hikari.maximumPoolSize=5

## PostgreSQL
spring.datasource.url=${DBURL}
spring.datasource.username=${DBUSER}
spring.datasource.password=${DBPASSWORD}

for debugging I also tried to put the real values there, but no difference. What now happen is following:

The rest of the code is unchanged, I have not yet added any JPA entities, other Controllers or Repositories (which is what I plan next). Also for testing I am still trying to call the ping.

2020-05-26T14:08:10.318+02:00 APPLICATION FAILED TO START

2020-05-26T14:08:10.318+02:00 Description:

2020-05-26T14:08:10.318+02:00 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

2020-05-26T14:08:10.318+02:00 Reason: Failed to determine a suitable driver class

2020-05-26T14:08:10.318+02:00 Action:

2020-05-26T14:08:10.318+02:00 Consider the following:

2020-05-26T14:08:10.318+02:00 If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.

2020-05-26T14:08:10.318+02:00 If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

Sorry this is maybe a very stupid questions for the experts, but I am new to Spring. It would be really great if there would be a full working skeleton example with using JPA entities connecting to an existing DB and exposing via REST. Thanks a lot! manuel

Expected behavior

Connect to DB using JPA and expose Data via REST.

Actual behavior

Getting Failed to configure a DataSource: 'url' attribute is not specified

Steps to reproduce

see above

Full log output

see above

kawa9 commented 4 years ago

Hi, closing this as I got it working. Some findings: