開発環境EclipseでSpring Batchを使用しバッチアプリケーションを作成しています。
Eclipse上で実行に成功しましたが、コマンドからの実行でエラーが発生してしまいます。
解消方法を教えていただきたく思います。
Eclipse環境上では以下で実行ができました。
Javaアプリケーションの実行構成
・メイン・クラス(M):org.springframework.batch.core.launch.support.CommandLineJobRunner
・プログラムの引数(A):com.test.batch.BatchJob job
で設定し実行
BatchJobはJavaで作成したJobクラスを指します。
jobはJavaクラス内の起動Jobを指します。
application.propertiesの構成は以下となります。
この問題解消後外だしする予定です。
xml
1#接続DB設定(テスト用) 2spring.datasource.url=jdbc:oracle:thin:@○○○○○:○○○ 3spring.datasource.username=○○○○○○ 4spring.datasource.password=○○○○○○ 5spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver 6 7#メタテーブルDDL実行制御 8spring.batch.initializer.enabled=false
問題となっているコマンドプロンプトからの実行方法は以下となります。
①Eclipse上で対象プロジェクトを右クリック→「実行」→「Maven clean」→「Maven install」
target配下に実行用TestBatch.jarが作成される。
②TestBatch.jarを[C:\test\kidou]に配置
③コマンドプロンプトで[C:\test\kidou]に移動し、
[java -jar TestBatch.jar org.springframework.batch.core.launch.support.CommandLineJobRunner BOOT-INF/classes/com/test/batch/TestBatch job]をたたく
コマンドは↓様を参考にさせていただきました。
http://javatechnology.net/spring/spring-batch-job-execute-jar/
発生している問題・エラーメッセージ
2018-11-25 20:53:45.507[main][INFO ][com.test.batch.BatchApplication] No active profile set, falling back to default profiles: default 2018-11-25 20:53:46.765[main][WARN ][org.springframework.context.annotation.AnnotationConfigApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testTableDao' defined in URL [jar:file:/C:/test/kidou/TestBatch.jar!/BOOT-INF/classes!/com/test/db/dao/TestTableDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' 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 java.lang.IllegalStateException: Cannot load driver class: oracle.jdbc.driver.OracleDriver 2018-11-25 20:53:46.777[main][INFO ][org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener] Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2018-11-25 20:53:46.783[main][ERROR][org.springframework.boot.SpringApplication] Application run failed
oraclejdbcに関するエラーですが、
jar作成後にjarの中を見てみると
C:\test\kidou\TestBatch.jar\BOOT-INF\libにoraclejdbc以外の依存関係は入っていました。
oraclejdbcは含まれていなかったため、jarファイルと同ディレクトリにjdbcを配置し、
環境変数-システム環境変数のCLASSPATHにC:\test\kidou\ojdbc8.jarを指定しましたが、エラー内容は変わりませんでした。
Eclipse上では動作したため、oraclejdbcのパスの通し方や実行時のコマンドの指定に誤りがあるかと思います。
多くのサイトを拝見しましたが解決できずにいます。
コマンドでの実行で正常に動作できる方法を教えていただきたく思います。
回答2件
あなたの回答
tips
プレビュー