前提・実現したいこと
SpringBoot + Spring JPA + PostgreSQLでAmazon RDSに格納したデータを出し入れするWebAPIを作成しています。
ローカル環境では正常起動しRDSへの接続も確認できているのですが、
パッケージを実行可能なJARとしてエクスポート(必須ライブラリをサブフォルダーにコピー)し、EC2上のLinux2環境に乗せてjavaコマンドで実行した際に下記エラーが発生しました。
似たような質問を読み漁り、解決を試みたものの、根本原因及び解決方法が見つからないので質問させていただきます。
発生している問題・エラーメッセージ
/\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ / _` | \ \ \ \ \/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.4.2) 2021-02-16 11:11:02.872 INFO 62498 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication using Java 11.0.10 on ip-xxx-xx-xx-xx.ap-northeast-1.compute.internal with PID 62498 (/home/ec2-user/sample.jar started by root in /home/ec2-user) 2021-02-16 11:11:02.875 INFO 62498 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default 2021-02-16 11:11:04.003 INFO 62498 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2021-02-16 11:11:04.113 INFO 62498 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 83 ms. Found 4 JPA repository interfaces. 2021-02-16 11:11:05.834 INFO 62498 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2021-02-16 11:11:05.856 INFO 62498 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2021-02-16 11:11:05.857 INFO 62498 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41] 2021-02-16 11:11:05.977 INFO 62498 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2021-02-16 11:11:05.977 INFO 62498 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3022 ms 2021-02-16 11:11:06.549 WARN 62498 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class 2021-02-16 11:11:06.552 INFO 62498 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2021-02-16 11:11:06.602 INFO 62498 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2021-02-16 11:11:06.641 ERROR 62498 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class Action: Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
apprication.properties
spring.jpa.database=POSTGRESQL spring.datasource.driver-class-name=org.postgresql.Driver spring.datasource.url=jdbc:postgresql://database-x.xxxxx.ap-northeast-1.rds.amazonaws.com:5432/testdb spring.datasource.username=username spring.datasource.password=password
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.2</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name> <description>Demo project for Spring Boot</description> <properties> <java.version>11</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
試したこと
・プロジェクトのクリーン
・[Maven(M)]-[プロジェクトの更新]
補足情報(FW/ツールのバージョンなど)
Demo project for Spring Boot
Maven
Java 11
追記
EC2インスタンスのコンソール上からpsqlコマンドによるRDSへのアクセスは問題なくできています。
あなたの回答
tips
プレビュー