質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Amazon RDS

Amazon RDSは、米アマゾン社が提供しているRDBMSサービス。クラウド上でのリレーショナルデータベースの構築および運用が可能です。MySQL/PostgreSQL/Oracle/SQL Serverのインストールを容易にすることができます。

JAR

JAR(又はJava ARchive)はコンパイルされた複数のJavaバイトコード及び関連ファイルのリソースを一つのファイルに統合したものです。JARファイルはZIPファイルのフォーマットで構築されています。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Apache Maven

Apache Mavenは、ソフトウェアプロジェクトの管理ツールです。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

解決済

1回答

1287閲覧

springアプリケーションをMaven installでjar化するときにエラー発生

kachikata96

総合スコア28

Amazon RDS

Amazon RDSは、米アマゾン社が提供しているRDBMSサービス。クラウド上でのリレーショナルデータベースの構築および運用が可能です。MySQL/PostgreSQL/Oracle/SQL Serverのインストールを容易にすることができます。

JAR

JAR(又はJava ARchive)はコンパイルされた複数のJavaバイトコード及び関連ファイルのリソースを一つのファイルに統合したものです。JARファイルはZIPファイルのフォーマットで構築されています。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Apache Maven

Apache Mavenは、ソフトウェアプロジェクトの管理ツールです。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2020/07/07 10:19

学習の一環として、eclipse2019.4.14、Java1.8、SpringBoot(2.0.4.RELEASE)、MySQL5.7による開発を行っております。
サーバーはAWSのEC2(OSはAmazonLinux2)を使用しています。
データベースはAWSの学習も兼ねてRDSを使います。
最終的にはデータベースも利用した動的webページをweb上に公開したいと思っています。

EC2とRDSの設定も終わったので試しにRDSにあるデータベースに接続するspringアプリケーションを
Maven installを使いjarファイル化してEC2にデプロイしようと思いました。

しかし、Maven installを実行するとエラーが起きてしまいjarファイルにすることができなくなってしまいました.

エラーコードを読んでもはっきりとした原因わからず困っています。

どうすればこのエラーを解決してjarファイルにすることができるでしょうか。

※elipseからspringアプリケーションで実行したときは問題なく起動でき、RDSにあるデータベースに接続できていることも確認しました。

エラー内容

一部抜粋

2020-07-07 18:26:02.978 INFO 14136 --- [ main] o.s.t.c.transaction.TransactionContext : Rolled back transaction for test: [DefaultTestContext@25435731 testClass = UserDaoTest, testInstance = com.example.demo.UserDaoTest@20163008, testMethod = countTest2@UserDaoTest, testException = java.lang.AssertionError: expected:<4> but was:<3>, mergedContextConfiguration = [WebMergedContextConfiguration@5cd6719d testClass = UserDaoTest, locations = '{}', classes = '{class com.example.demo.SpringSampleApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@15d9bc04, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@646be2c3, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@176d53b2, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@7f9fcf7f], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.populatedRequestContextHolder' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.resetRequestContextHolder' -> true]] [ERROR] Tests run: 2, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 1.062 s <<< FAILURE! - in com.example.demo.UserDaoTest [ERROR] countTest1(com.example.demo.UserDaoTest) Time elapsed: 0.53 s <<< FAILURE! java.lang.AssertionError: expected:<3> but was:<2> at com.example.demo.UserDaoTest.countTest1(UserDaoTest.java:30) [ERROR] countTest2(com.example.demo.UserDaoTest) Time elapsed: 0.413 s <<< FAILURE! java.lang.AssertionError: expected:<4> but was:<3> at com.example.demo.UserDaoTest.countTest2(UserDaoTest.java:39) 2020-07-07 18:26:03.080 INFO 14136 --- [ Thread-7] o.s.w.c.s.GenericWebApplicationContext : Closing org.springframework.web.context.support.GenericWebApplicationContext@3b5da0b0: startup date [Tue Jul 07 18:25:52 JST 2020]; root of context hierarchy 2020-07-07 18:26:03.082 INFO 14136 --- [ Thread-4] o.s.w.c.s.GenericWebApplicationContext : Closing org.springframework.web.context.support.GenericWebApplicationContext@7dfd3c81: startup date [Tue Jul 07 18:25:38 JST 2020]; root of context hierarchy 2020-07-07 18:26:03.086 INFO 14136 --- [ Thread-9] o.s.w.c.s.GenericWebApplicationContext : Closing org.springframework.web.context.support.GenericWebApplicationContext@2bc59ab7: startup date [Tue Jul 07 18:25:57 JST 2020]; root of context hierarchy 2020-07-07 18:26:03.096 INFO 14136 --- [ Thread-4] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2020-07-07 18:26:03.105 INFO 14136 --- [ Thread-9] com.zaxxer.hikari.HikariDataSource : HikariPool-3 - Shutdown initiated... 2020-07-07 18:26:03.107 INFO 14136 --- [ Thread-7] com.zaxxer.hikari.HikariDataSource : HikariPool-2 - Shutdown initiated... 2020-07-07 18:26:03.172 INFO 14136 --- [ Thread-4] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. 2020-07-07 18:26:03.188 INFO 14136 --- [ Thread-7] com.zaxxer.hikari.HikariDataSource : HikariPool-2 - Shutdown completed. 2020-07-07 18:26:03.283 INFO 14136 --- [ Thread-9] com.zaxxer.hikari.HikariDataSource : HikariPool-3 - Shutdown completed. [INFO] [INFO] Results: [INFO] [ERROR] Failures: [ERROR] UserDaoTest.countTest1:30 expected:<3> but was:<2> [ERROR] UserDaoTest.countTest2:39 expected:<4> but was:<3> [INFO] [ERROR] Tests run: 5, Failures: 2, Errors: 0, Skipped: 0 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 33.956 s [INFO] Finished at: 2020-07-07T18:26:03+09:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) on project SpringSample: There are test failures. [ERROR] [ERROR] Please refer to C:\Users\admin\Desktop\testWorkSpace3\SpringSample2\target\surefire-reports for the individual test results. [ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream. [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

詳細については\target\surefire-reports を参考にしろとエラーコードに書かれていたので参考になりそうなエラー文も載せておきます。

どうやらUserDaoテストでエラーが起きたようです。

------------------------------------------------------------------------------- Test set: com.example.demo.UserDaoTest ------------------------------------------------------------------------------- Tests run: 2, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 1.062 s <<< FAILURE! - in com.example.demo.UserDaoTest countTest1(com.example.demo.UserDaoTest) Time elapsed: 0.53 s <<< FAILURE! java.lang.AssertionError: expected:<3> but was:<2> at com.example.demo.UserDaoTest.countTest1(UserDaoTest.java:30) countTest2(com.example.demo.UserDaoTest) Time elapsed: 0.413 s <<< FAILURE! java.lang.AssertionError: expected:<4> but was:<3> at com.example.demo.UserDaoTest.countTest2(UserDaoTest.java:39)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

テストケースでつなげるのはテストのたびにデータを破棄できる環境でなければいけません。
テストリソース等で接続先を変更しましょう。

データ件数が増えてしまい、件数不一致となっています。

投稿2020/07/07 10:56

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kachikata96

2020/07/07 11:33

そういうエラーだったのですね。 試しにtestクラスをすべて消したらうまくいきました。 ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問