有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用来自另一个模块的Bean

我正在创建一个批处理应用程序,将来自web服务的一些数据放到数据库中。 为此,我需要转换web服务在可利用类上接收的DTO。这可以使用其他模块中定义的映射器实现

当我尝试@Autowired映射器时,我遇到了一个例外,我不知道如何才能昏过去

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)}

地图绘制人员在他们的模块中工作正常。我可以@Autowierdd他们,并使用它没有问题。如果我不@Autowierd映射程序,我的批处理工作正常

有人有主意吗

谢谢

编辑

我的配置在我的作业配置类中:

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

我试着写:@ComponentScan(basePackages = {"com.execution.batch", "com.execution.serve"})

但如果我这样做,我会向工作bean的注入报告错误:

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: {}

就像我说的,单独的模块可以很好地工作

  • 当我扫描服务器和批处理模块时,批处理的扫描不起作用
  • 当我只扫描批处理模块时,服务器模块不工作,因为我认为不是扫描

共 (1) 个答案

  1. # 1 楼答案

    我猜你忘了用你想要的类的适当包设置“扫描器”

    你的bean是utilisateurProcessor,fqn是com.execution.batch.processor.UtilisateurProcessor。它是配置为@组件还是在XML中

    请粘贴spring的配置,以查看是否已将com.execution.server.common.mapper添加到spring的扫描仪