質問編集履歴

9

2018/10/22 22:04

投稿

star0415
star0415

スコア25

test CHANGED
File without changes
test CHANGED
@@ -20,6 +20,8 @@
20
20
 
21
21
  後はdatasourceの設定ファイルの書き方がわかりません。どのように定義すればよろしいでしょうか?ファイル名とファイルの書き方をご教示ください。
22
22
 
23
+ DBはpostgresです。
24
+
23
25
  -----
24
26
 
25
27
 

8

2018/10/22 22:04

投稿

star0415
star0415

スコア25

test CHANGED
File without changes
test CHANGED
@@ -6,15 +6,21 @@
6
6
 
7
7
  解決方法をご教示いただけますでしょうか?
8
8
 
9
-
9
+ https://dzone.com/articles/spring-batch-csv-processing
10
+
11
+
12
+
13
+
14
+
15
+ -----
16
+
17
+ 追記
10
18
 
11
19
  javax.batch.api.jarファイルを設定するとエラー内容が変わりました。
12
20
 
13
21
  後はdatasourceの設定ファイルの書き方がわかりません。どのように定義すればよろしいでしょうか?ファイル名とファイルの書き方をご教示ください。
14
22
 
15
-
16
-
17
- https://dzone.com/articles/spring-batch-csv-processing
23
+ -----
18
24
 
19
25
 
20
26
 

7

2018/10/22 09:23

投稿

star0415
star0415

スコア25

test CHANGED
File without changes
test CHANGED
File without changes

6

2018/10/22 08:41

投稿

star0415
star0415

スコア25

test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  javax.batch.api.jarファイルを設定するとエラー内容が変わりました。
12
12
 
13
- 後はdatasourceの設定方がわかりません。どのように定義すればよろしいでしょうか?
13
+ 後はdatasourceの設定ファイルの書き方がわかりません。どのように定義すればよろしいでしょうか?ファイル名とファイルの書き方をご教示ください。
14
14
 
15
15
 
16
16
 
@@ -210,12 +210,6 @@
210
210
 
211
211
 
212
212
 
213
- 設定が足りてないとの回答をいただきましたが設定ファイルの書き方がわかりません。
214
-
215
- 関係ありそうなソースを記述しました。
216
-
217
-
218
-
219
213
  エラー内容
220
214
 
221
215
  [2018-10-22 09:12:07.464] - 16092 重大 [main] --- org.springframework.boot.SpringApplication: Application run failed

5

2018/10/22 08:41

投稿

star0415
star0415

スコア25

test CHANGED
File without changes
test CHANGED
@@ -6,6 +6,14 @@
6
6
 
7
7
  解決方法をご教示いただけますでしょうか?
8
8
 
9
+
10
+
11
+ javax.batch.api.jarファイルを設定するとエラー内容が変わりました。
12
+
13
+ 後はdatasourceの設定方法がわかりません。どのように定義すればよろしいでしょうか?
14
+
15
+
16
+
9
17
  https://dzone.com/articles/spring-batch-csv-processing
10
18
 
11
19
 

4

2018/10/22 07:56

投稿

star0415
star0415

スコア25

test CHANGED
File without changes
test CHANGED
@@ -10,6 +10,204 @@
10
10
 
11
11
 
12
12
 
13
+ ```java
14
+
15
+ package com.michaelcgood;
16
+
17
+
18
+
19
+ import javax.sql.DataSource;
20
+
21
+
22
+
23
+ import org.springframework.batch.core.Job;
24
+
25
+ import org.springframework.batch.core.Step;
26
+
27
+ import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
28
+
29
+ import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
30
+
31
+ import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
32
+
33
+ import org.springframework.batch.core.launch.support.RunIdIncrementer;
34
+
35
+ import org.springframework.batch.item.ItemProcessor;
36
+
37
+ import org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider;
38
+
39
+ import org.springframework.batch.item.database.JdbcBatchItemWriter;
40
+
41
+ import org.springframework.batch.item.file.FlatFileItemReader;
42
+
43
+ import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
44
+
45
+ import org.springframework.batch.item.file.mapping.DefaultLineMapper;
46
+
47
+ import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
48
+
49
+ import org.springframework.beans.factory.annotation.Autowired;
50
+
51
+ import org.springframework.context.annotation.Bean;
52
+
53
+ import org.springframework.context.annotation.Configuration;
54
+
55
+ import org.springframework.core.io.ClassPathResource;
56
+
57
+
58
+
59
+ @EnableBatchProcessing
60
+
61
+ @Configuration
62
+
63
+ public class CsvFileToDatabaseConfig {
64
+
65
+
66
+
67
+ @Autowired
68
+
69
+ public JobBuilderFactory jobBuilderFactory;
70
+
71
+
72
+
73
+ @Autowired
74
+
75
+ public StepBuilderFactory stepBuilderFactory;
76
+
77
+
78
+
79
+ @Autowired
80
+
81
+ public DataSource dataSource;
82
+
83
+
84
+
85
+ // begin reader, writer, and processor
86
+
87
+
88
+
89
+
90
+
91
+ @Bean
92
+
93
+ public FlatFileItemReader<AnimeDTO> csvAnimeReader(){
94
+
95
+ FlatFileItemReader<AnimeDTO> reader = new FlatFileItemReader<AnimeDTO>();
96
+
97
+ reader.setResource(new ClassPathResource("animescsv.csv"));
98
+
99
+ reader.setLineMapper(new DefaultLineMapper<AnimeDTO>() {{
100
+
101
+ setLineTokenizer(new DelimitedLineTokenizer() {{
102
+
103
+ setNames(new String[] { "id", "title", "description" });
104
+
105
+ }});
106
+
107
+ setFieldSetMapper(new BeanWrapperFieldSetMapper<AnimeDTO>() {{
108
+
109
+ setTargetType(AnimeDTO.class);
110
+
111
+ }});
112
+
113
+ }});
114
+
115
+ return reader;
116
+
117
+ }
118
+
119
+
120
+
121
+
122
+
123
+ @Bean
124
+
125
+ ItemProcessor<AnimeDTO, AnimeDTO> csvAnimeProcessor() {
126
+
127
+ return new AnimeProcessor();
128
+
129
+ }
130
+
131
+
132
+
133
+ @Bean
134
+
135
+ public JdbcBatchItemWriter<AnimeDTO> csvAnimeWriter() {
136
+
137
+ JdbcBatchItemWriter<AnimeDTO> csvAnimeWriter = new JdbcBatchItemWriter<AnimeDTO>();
138
+
139
+ csvAnimeWriter.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<AnimeDTO>());
140
+
141
+ csvAnimeWriter.setSql("INSERT INTO animes (id, title, description) VALUES (:id, :title, :description)");
142
+
143
+ csvAnimeWriter.setDataSource(dataSource);
144
+
145
+ return csvAnimeWriter;
146
+
147
+ }
148
+
149
+
150
+
151
+ // end reader, writer, and processor
152
+
153
+
154
+
155
+ // begin job info
156
+
157
+ @Bean
158
+
159
+ public Step csvFileToDatabaseStep() {
160
+
161
+ return stepBuilderFactory.get("csvFileToDatabaseStep")
162
+
163
+ .<AnimeDTO, AnimeDTO>chunk(1)
164
+
165
+ .reader(csvAnimeReader())
166
+
167
+ .processor(csvAnimeProcessor())
168
+
169
+ .writer(csvAnimeWriter())
170
+
171
+ .build();
172
+
173
+ }
174
+
175
+
176
+
177
+ @Bean
178
+
179
+ Job csvFileToDatabaseJob(JobCompletionNotificationListener listener) {
180
+
181
+ return jobBuilderFactory.get("csvFileToDatabaseJob")
182
+
183
+ .incrementer(new RunIdIncrementer())
184
+
185
+ .listener(listener)
186
+
187
+ .flow(csvFileToDatabaseStep())
188
+
189
+ .end()
190
+
191
+ .build();
192
+
193
+ }
194
+
195
+ // end job info
196
+
197
+ }
198
+
199
+
200
+
201
+ ```
202
+
203
+
204
+
205
+ 設定が足りてないとの回答をいただきましたが設定ファイルの書き方がわかりません。
206
+
207
+ 関係ありそうなソースを記述しました。
208
+
209
+
210
+
13
211
  エラー内容
14
212
 
15
213
  [2018-10-22 09:12:07.464] - 16092 重大 [main] --- org.springframework.boot.SpringApplication: Application run failed

3

2018/10/22 06:56

投稿

star0415
star0415

スコア25

test CHANGED
File without changes
test CHANGED
File without changes

2

2018/10/22 01:53

投稿

star0415
star0415

スコア25

test CHANGED
File without changes
test CHANGED
@@ -1,49 +1,57 @@
1
- ### 前提・実現したいこと
1
+ お世話になります。
2
2
 
3
3
 
4
4
 
5
- ここに質問内容を詳しく書いください。
5
+ 以下ページのspring bootアプリケーションの実行でエラーが起き困ってます
6
6
 
7
- (例)PHP(CakePHP)で●●なシステム作っています
7
+ 解決方法ご教示ただけますでしょうか?
8
8
 
9
- ■■な機能を実装中に以下のエラーメッセージが発生しました。
9
+ https://dzone.com/articles/spring-batch-csv-processing
10
10
 
11
11
 
12
12
 
13
- ### 発生している問題・エラーメッセージ
13
+ エラー内容
14
14
 
15
+ [2018-10-22 09:12:07.464] - 16092 重大 [main] --- org.springframework.boot.SpringApplication: Application run failed
15
16
 
17
+ org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'csvFileToDatabaseConfig': Unsatisfied dependency expressed through field 'jobBuilderFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobBuilders' defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.batch.core.configuration.annotation.JobBuilderFactory]: Factory method 'jobBuilders' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.batch.core.repository.JobRepository]: Factory method 'jobRepository' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/batch/runtime/JobInstance
16
18
 
17
- ```
19
+ at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)
18
20
 
19
- エラーメッセージ
21
+ at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
20
22
 
21
- ```
23
+ at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374)
22
24
 
25
+ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1378)
23
26
 
27
+ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575)
24
28
 
25
- ### 該当のソースコード
29
+ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
26
30
 
31
+ at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
27
32
 
33
+ at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
28
34
 
29
- ```ここに言語名を入力
35
+ at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
30
36
 
31
- ソースコード
37
+ at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
32
38
 
33
- ```
39
+ at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846)
34
40
 
41
+ at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863)
35
42
 
43
+ at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
36
44
 
37
- ### 試したこと
45
+ at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
38
46
 
47
+ at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386)
39
48
 
49
+ at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
40
50
 
41
- ここに問題に対して試したことを記載してください。
51
+ at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242)
42
52
 
53
+ at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230)
43
54
 
55
+ at com.michaelcgood.SpringBatchCsvApplication.main(SpringBatchCsvApplication.java:10)
44
56
 
45
- ### 補足情報(FW/ツールのバージョンなど)
46
-
47
-
48
-
49
- ここにより詳細な情報を記載してください。
57
+ Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobBuilders' defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.

1

2018/10/22 01:32

投稿

star0415
star0415

スコア25

test CHANGED
File without changes
test CHANGED
File without changes