Bonjour tous le monde,
Mon problème est le suivant:
je veux lire d'une base de donnée(ItemReader) et je veux écrire dans une autre base de donnée(ItemWriter).
Voici mon bout de code utilisé:
Voici les deux transactions managers avec les deux data sources utilisées
Voici la déclaration de joblauncher et de job repository :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 <bean id="jobtransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" lazy-init="true"> <property name="dataSource" ref="jobdataSource" /> </bean> <bean id="jobtransactionManagerStkFin" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" lazy-init="true"> <property name="dataSource" ref="stkfinDataSource" /> </bean> <bean id="jobdataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy"> <property name="targetDataSource"> <bean class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="resourceRef"> <value>true</value> </property> <property name="jndiName"> <value>jdbc/dbds</value> </property> </bean> </property> </bean> <bean id="stkfinDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy"> <property name="targetDataSource"> <bean class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="resourceRef"> <value>true</value> </property> <property name="jndiName"> <value>jdbc/dbstkfin</value> </property> </bean> </property> </bean>
Voici la déclaration de job ainsi que le step et ItemReader avec la première datasource stkfinDataSource et ItemWriter avec la deuxième data source jobdataSource
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 <bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> <property name="jobRepository" ref="jobRepository" /> </bean> <batch:job-repository id="jobRepository" data-source="jobdataSource" transaction-manager="jobtransactionManager" table-prefix="BATCH_" max-varchar-length="1000" />
Est-ce-que on peut lire d'une base et écrire dans une autre base dans spring batch?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 <batch:job id="chargementModemTunetJob" job-repository="jobRepository"> <batch:step id="chargementModemTunetStepStart" parent="chargementModemTunetStep" /> </batch:job> <batch:step id="chargementModemTunetStep"> <batch:tasklet transaction-manager="jobtransactionManager"> <batch:chunk reader="chargementModemTunetCursorItemReader" writer="chargementModemTunetItemWriter" commit-interval="1000" /> </batch:tasklet> </batch:step> <bean id="chargementModemTunetCursorItemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader"> <property name="dataSource" ref="stkfinDataSource" /> <property name="rowMapper" ref="chargementModemTunetRowMapper" /> <property name="sql"> <value> select l.rang_deb,l.cod_prod from bon_liv_reel b,detail_liv_reel l WHERE b.cod_cent = l.cod_cent AND b.cod_exe = l.cod_exe AND b.num_doc = l.num_doc AND b.cod_cent like 'TOT%' AND b.dat_crea >to_date('01/02/2012','dd/mm/yyyy') </value> </property> </bean> <bean id="chargementModemTunetRowMapper" class="com.tunisiana.storecashnet.batch.ChargementModemSqlMapper"> </bean> <bean id="chargementModemTunetItemWriter" class="com.tunisiana.storecashnet.batch.ChargementModemTunetWriter"> <property name="chargementModemTunetService" ref="chargementModemTunetService" /> </bean> <bean id="chargementModemTunetService" class="com.tunisiana.storecashnet.service.batch.impl.ChargementModemTunetService"> <property name="chargementModemTunetDAO" ref="chargementModemTunetDAO" /> </bean> <bean id="chargementModemTunetDAO" class="com.tunisiana.storecashnet.dao.batch.impl.ChargementModemTunetDAO"> <property name="dataSource" ref="jobdataSource" /> </bean>
Merci Beaucoup d'avance.
Partager