2016-12-07 7 views
0

ich eine Batch-Anwendung erstellen auf der Datenbank, einige Daten von einem Web-Dienst zu stellen. Um dies zu tun, muss ich DTOs, die vom Web-Service empfangen werden, in nutzbare Klassen konvertieren. Dies ist mit einem Mapper möglich, der in einem anderen Modul definiert ist.Verwenden Bean aus einem anderen Modul

Als ich versuchte, die Mapper Ich habe eine Ausnahme @Autowierd und ich finde nicht, wie aus passieren.

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.execution.batch.processor.UtilisateurProcessor com.execution.batch.jobConfiguration.JobConfigurationAbstract.utilisateurProcessor; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'utilisateurProcessor': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.execution.server.common.mapper.UtilisateurMapper com.execution.batch.processor.UtilisateurProcessor.utilisateurMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.execution.server.common.mapper.UtilisateurMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
**Caused by**: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.execution.batch.processor.UtilisateurProcessor com.execution.batch.jobConfiguration.JobConfigurationAbstract.utilisateurProcessor; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'utilisateurProcessor': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.execution.server.common.mapper.UtilisateurMapper com.execution.batch.processor.UtilisateurProcessor.utilisateurMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.execution.server.common.mapper.UtilisateurMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
**Caused by**: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'utilisateurProcessor': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.execution.server.common.mapper.UtilisateurMapper com.execution.batch.processor.UtilisateurProcessor.utilisateurMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.execution.server.common.mapper.UtilisateurMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
**Caused by**: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.execution.server.common.mapper.UtilisateurMapper com.execution.batch.processor.UtilisateurProcessor.utilisateurMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.execution.server.common.mapper.UtilisateurMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
**Caused by**: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.execution.server.common.mapper.UtilisateurMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 

Die Mapper arbeiten gut in ihrem Modul. Ich kann sie @autowierdd und ohne Probleme nutzen. Und das meine Batch funktioniert einwandfrei wenn ich den Mapper nicht @autowierd habe.

Jemand hat eine Idee?

Danke!

EDIT

Meine Konfiguration ist auf meinen Job Konfigurationsklasse:

@Configuration 
@EnableBatchProcessing 
@ComponentScan(basePackages = {"com.execution.batch"}) 

ich zu setzen versucht: @ComponentScan(basePackages = {"com.execution.batch", "com.execution.serve"})

Aber wenn ich tun, dass ich auf die Injektion gemeldeten Fehler haben, die Bohne des Jobs:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.batch.core.configuration.annotation.StepBuilderFactory com.execution.batch.jobConfiguration.JobConfigurationAbstract.stepBuilderFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stepBuilders' 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.StepBuilderFactory]: Factory method 'stepBuilders' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jobRepository' defined in com.execution.batch.jobConfiguration.JobConfiguration: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager]: : No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} 
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.batch.core.configuration.annotation.StepBuilderFactory com.execution.batch.jobConfiguration.JobConfigurationAbstract.stepBuilderFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stepBuilders' 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.StepBuilderFactory]: Factory method 'stepBuilders' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jobRepository' defined in com.execution.batch.jobConfiguration.JobConfiguration: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager]: : No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stepBuilders' 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.StepBuilderFactory]: Factory method 'stepBuilders' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jobRepository' defined in com.execution.batch.jobConfiguration.JobConfiguration: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager]: : No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} 
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jobRepository' defined in com.execution.batch.jobConfiguration.JobConfiguration: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager]: : No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} 
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} 

Wie gesagt, die Module funktionieren separat.

  • Wenn ich den Server und das Stapelmodul scanne, funktioniert der Scan des Stapels nicht.
  • Wenn ich nur das Batch-Modul scannen, funktioniert das Servermodul nicht, weil ich nicht scanne.
  • +0

    Können Sie Ihre Konfiguration angeben? –

    Antwort

    0

    Ich denke, dass Sie vergessen haben, den "Scanner" mit dem entsprechenden Paket der gewünschten Klasse zu setzen.

    Ihre Bean ist utilisateurProcessor, FQN ist com.execution.batch.processor.UtilisateurProcessor. Ist es als @Component oder in Ihrem XML konfiguriert?

    Bitte fügen Sie den Frühling‘config, um zu sehen, ob Sie com.execution.server.common.mapper zu Spring-Scanner hinzugefügt haben.

    +0

    Sie können jetzt meine Konfiguration sehen: Ich verwende @ComponentScan. –

    +0

    versuchen Sie dies: @ComponentScan ("com.execution.batch") – OhadR

    +0

    Funktioniert nicht wegen der Injektion von Server-Bean. –

    0

    Da Ihre Konfigurationen unabhängig voneinander arbeiten, gibt es eine gute Änderung, die Sie in beiden Paketen in Konflikt stehenden Namen haben. Dies kann dazu führen, dass Konfigurationen oder Beans überschrieben werden.

    z.

    Als der Beanname im Springcontext wird nur der Klassenname ohne das Paket verwendet. Wenn Sie also beide Pakete scannen, wird nur eine Configuration-Class verarbeitet. Das Gleiche gilt auch für Klassen, die mit @Component annotiert sind.

    Es ist wichtig zu verstehen, dass @Component und @Configuration Klassen auch als Bohnen instanziiert werden, mit dem einfachen Klassennamen als BeanName.

    mit @Bean Auch annoted Methoden eine potentielle Fehlerquelle sind. Wenn Sie in zwei verschiedenen Configuration-Beans denselben Methodennamen haben, wird nur einer instanziert.

    Darüber hinaus, wenn Sie als @Bean Methodenname den gleichen Namen wie eine @Configuration Klassenname hat, dann wird wieder einer von der anderen überschrieben.

    +0

    Die Konfiguration für das andere Projekt ist eine XML-Konfiguration. Und keine Bohne oder Klasse haben denselben Namen. –

    +0

    Wie fügen Sie die xml-Konfiguration des "anderen Projekts" zur JavaApi-Konfiguration hinzu? Verwenden Sie '@ImportResource'? –

    +0

    ich müde setzen "@ImportResource (" classpath *: root-applicationContext.xml ")" In der Konfiguration-Job-Klasse oder in der Application-Klasse (Haupt), Stahl funktioniert nicht. Das andere Projekt "dienen" ist ein Krieg, das kann ein Problem sein? –

    Verwandte Themen