Bonjour,
Je bosse actuellement sur un projet qui s’appuit sur le framework spring-batch 3.0.6, tout s'est bien passé : j'ai terminé le dév, les tests, j'en suis maintenant au déploiement et j'ai un petit soucis.
J'utilise maven et le plug-in one-jar qui me permettent de générer un seul jar avec toutes les dépendances.
Lorsque je lance l'éxecution de mon jar avec la commande "java -jar mon_batch-1.0.0.one-jar.jar launch-context.xml job1 -next", j'ai le message suivant dans ma log :
A savoir que ma dataSource est défini par annotation dans la classe suivante :main 16:54:20,535 ERROR CommandLineJobRunner:355 - Job Terminated in error: Error creating bean with name 'jobRepository': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSource' is defined
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSource' is defined
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
Dans le fichier launch-context.xml, j'ai défini vers le fichier batch.properties qui contient les informations pour la création du datasource.
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
52
53
54
55
56 package com.monpackage; import javax.sql.DataSource; import org.apache.commons.dbcp.BasicDataSource; import org.springframework.batch.core.launch.support.SimpleJobLauncher; import org.springframework.batch.core.repository.JobRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.transaction.PlatformTransactionManager; @Configuration public class MaConfiguration { @Value("${batch.jdbc.driver}") private String driverClassName; @Value("${batch.jdbc.url}") private String driverUrl; @Value("${batch.jdbc.user}") private String driverUsername; @Value("${batch.jdbc.password}") private String driverPassword; @Autowired @Qualifier("jobRepository") private JobRepository jobRepository; @Bean public DataSource dataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driverClassName); dataSource.setUrl(driverUrl); dataSource.setUsername(driverUsername); dataSource.setPassword(driverPassword); return dataSource; } @Bean public SimpleJobLauncher jobLauncher() { SimpleJobLauncher jobLauncher = new SimpleJobLauncher(); jobLauncher.setJobRepository(jobRepository); return jobLauncher; } @Bean public PlatformTransactionManager transactionManager() { return new DataSourceTransactionManager(dataSource()); } }
Pour contourner, j'ai bien entendu essayer de redéfinir le bean dans le xml de l'application mais ca plante alors au moment du rechercher le transactionManager ...
De plus, en faisant ainsi, je n'utiliserai plus les annotations et j'aimerais bien comprendre d'où vient le problème surtout que cela fonctionne très bien quand je lance depuis eclispe ...
Merci de votre attention, en espérant que vous pourrez m'éclairer.
Partager