質問編集履歴
2
SampleTableRepositoryImplの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -144,6 +144,16 @@
|
|
144
144
|
|
145
145
|
```
|
146
146
|
|
147
|
+
SampleTableRepositoryImpl.java
|
148
|
+
|
149
|
+
```Java
|
150
|
+
|
151
|
+
public class SampleTableRepositoryImpl {}
|
152
|
+
|
153
|
+
```
|
154
|
+
|
155
|
+
|
156
|
+
|
147
157
|
applicationContext.xml
|
148
158
|
|
149
159
|
```xml
|
1
ソースを記載
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
SpringBatchでAutowireしたい
|
1
|
+
SpringBatchでAutowiredしたい
|
test
CHANGED
@@ -72,17 +72,157 @@
|
|
72
72
|
|
73
73
|
|
74
74
|
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
75
79
|
###該当のソースコード
|
76
80
|
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
MyBatchJob.java
|
86
|
+
|
87
|
+
```java
|
88
|
+
|
89
|
+
public class MyBatchJob implements Tasklet {
|
90
|
+
|
91
|
+
static Logger logger = Logger.getLogger("MyBatch");
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
@PersistenceContext(type = PersistenceContextType.EXTENDED)
|
96
|
+
|
97
|
+
private EntityManager entityManager;
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
@Autowired
|
102
|
+
|
103
|
+
private SampleTableRepository sampleTableRepo;
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
public RepeatStatus execute(StepContribution arg0, ChunkContext arg1)
|
108
|
+
|
109
|
+
throws Exception {
|
110
|
+
|
111
|
+
SampleTableEntity sampleTable = new SampleTableEntity();
|
112
|
+
|
113
|
+
sampleTable.setName("test name");
|
114
|
+
|
115
|
+
sampleTable.setStatus(100);
|
116
|
+
|
117
|
+
entityManager.persist(sampleTable);
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
sampleTableRepo.findAll();
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
System.out.println("Created SampleTableEntity=" + sampleTable.getId());
|
126
|
+
|
127
|
+
return RepeatStatus.FINISHED;
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
```
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
SampleTableRepository.java
|
138
|
+
|
139
|
+
```java
|
140
|
+
|
141
|
+
@Repository
|
142
|
+
|
143
|
+
public interface SampleTableRepository extends JpaRepository<SampleTableEntity, Long> {}
|
144
|
+
|
145
|
+
```
|
146
|
+
|
147
|
+
applicationContext.xml
|
148
|
+
|
149
|
+
```xml
|
150
|
+
|
151
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
152
|
+
|
153
|
+
<beans xmlns="http://www.springframework.org/schema/beans"
|
154
|
+
|
155
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
156
|
+
|
157
|
+
xmlns:p="http://www.springframework.org/schema/p"
|
158
|
+
|
159
|
+
xmlns:context="http://www.springframework.org/schema/context"
|
160
|
+
|
161
|
+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
162
|
+
|
163
|
+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
<import resource="classpath:META-INF/spring/batchContext.xml"/>
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
<context:component-scan base-package="com.example.spring"/>
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean"/>
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"
|
180
|
+
|
181
|
+
p:jobRepository-ref="jobRepository"/>
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close"
|
186
|
+
|
187
|
+
p:driverClassName="com.mysql.jdbc.Driver"
|
188
|
+
|
189
|
+
p:url="jdbc:mysql://localhost/spring_test?zeroDateTimeBehavior=convertToNull"
|
190
|
+
|
191
|
+
p:username="root"
|
192
|
+
|
193
|
+
p:password=""/>
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
|
202
|
+
|
203
|
+
p:dataSource-ref="dataSource"
|
204
|
+
|
205
|
+
p:packagesToScan="com.example.spring"
|
206
|
+
|
207
|
+
p:jpaVendorAdapter-ref="jpaVendorAdapter"/>
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"/>
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
</beans>
|
216
|
+
|
217
|
+
```
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
プロジェクト
|
222
|
+
|
77
223
|
https://github.com/horitaku1124/spring_batch_sample/tree/master/SpringBatchSample1
|
78
224
|
|
79
|
-
|
225
|
+
|
80
|
-
|
81
|
-
@Autowired
|
82
|
-
|
83
|
-
private SampleTableRepository sampleTableRepo;
|
84
|
-
|
85
|
-
```
|
86
226
|
|
87
227
|
|
88
228
|
|