Skip to content

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

@kawa9

Description

@kawa9
  • Framework version: 1.5
  • Implementations: Spring Boot 2

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:

  • Running Spring Boot as Local Application works fine (Added a public CommandLineRunner demo() in the Application class). In log I can see Hikari Logs which seems perfectly fine, so it looks also connection to Db locally is working fine. No Errors at all.
  • If I deploy it (either deploy serverless project, or also package shade:shade and manually upload the JAR into the AWS Console Lambda) I keep getting this below whatever I put in application.properties. I get the feeling that someway the Lambda is not using the application.properties.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions