awslabs / aws-saas-boost

AWS SaaS Boost is a ready-to-use toolset that removes the complexity of successfully running SaaS workloads in the AWS cloud.
Apache License 2.0
954 stars 188 forks source link

Sample java can not start by Missing environment variable DB_NAME #532

Open hanchenglin opened 7 months ago

hanchenglin commented 7 months ago

Sample java can not start by Missing environment variable DB_NAME

How to fix jdbc config error

Error log:

2023-11-30T01:31:12.294+09:00 2023-11-29 16:31:12.293 ERROR 7 --- [ main] o.s.boot.SpringApplication : Application run failed

2023-11-30T01:31:12.294+09:00

Copy
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderDaoImpl': Unsatisfied dependency expressed through field 'jdbc'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getDataSource' defined in class path resource [com/amazon/aws/partners/saasfactory/configuration/DataSourceConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'getDataSource' threw exception; nested exception is java.lang.IllegalStateException: Missing environment variable DB_NAME
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderDaoImpl': Unsatisfied dependency expressed through field 'jdbc'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getDataSource' defined in class path resource [com/amazon/aws/partners/saasfactory/configuration/DataSourceConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'getDataSource' threw exception; nested exception is java.lang.IllegalStateException: Missing environment variable DB_NAME

Environment

Other information

I configed Postgres, also auto created database. I can not see where set env in https://github.com/awslabs/aws-saas-boost/blob/main/samples/java/Dockerfile

But sample java need env in https://github.com/awslabs/aws-saas-boost/blob/main/samples/java/src/main/java/com/amazon/aws/partners/saasfactory/configuration/DataSourceConfig.java#L35

    private static final String DB_NAME = System.getenv("DB_NAME");
    private static final String DB_HOST = System.getenv("DB_HOST");
    private static final String DB_PORT = System.getenv("DB_PORT");
    private static final String DB_USER = System.getenv("DB_USER");
    private static final String DB_PASSORD = System.getenv("DB_PASSWORD");
hanchenglin commented 7 months ago

There is config for DB_NAME, DB_HOST in https://github.com/awslabs/aws-saas-boost/blob/main/resources/tenant-onboarding-app.yaml#L582

image

hanchenglin commented 7 months ago

Sorry! I changed config can work now, but I think we shoud refactor item layout.

スクリーンショット 2023-12-01 0 27 15 1
brtrvn commented 7 months ago

See the instructions for Step 7 in the Getting Started guide. The database name is required for the sample app.

The database name is optional in the App Config form because a database name may not be required by your application (it may be hard coded in your app). Setting the database name in the App Config also triggers the RDS bootstrap Lambda during tenant onboarding.