Spring Package - Bean Creation Failure Autowire Fails

I'm new to Spring and Spring Batch. I'm working on setting up a Java configuration for the Spring batch job that I tested using the XML configuration that I am running correctly. However, I ran into a problem when I can’t even get the work to start the application due to a problem, I suppose, with the DataSource bean setting. I am going to dump errors here:

2016 - 11 - 22 16: 49: 59.819 WARN 20056---[main] o.s.c.a.ConfigurationClassEnhancer: @Bean method ScopeConfiguration.stepScope is non - static and returns an object assignable to Spring BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method declaring@ Configuration class.Add the 'static' modifier to this method to avoid these container lifecycle issues; see@ Bean javadoc for complete details.
2016 - 11 - 22 16: 49: 59.834 WARN 20056---[main] o.s.c.a.ConfigurationClassEnhancer: @Bean method ScopeConfiguration.jobScope is non - static and returns an object assignable to Spring  BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method declaring@ Configuration class.Add the 'static' modifier to this method to avoid these container lifecycle issues; see@ Bean javadoc for complete details.
Run codeHide result

I do not know where I am mistaken in the configuration because I followed the design patterns proposed by Spring and other tutorials. Since the bean is not created correctly, and the factory postprocess does not close it, Autowired cBeans breaks, which I configure in the ArchiveJobConfig class. Any help would be appreciated

Console exit

::Spring Boot::(v1.3.5.RELEASE)

 2016 - 11 - 22 16: 49: 58.315 INFO 20056---[main] c.s.batch.jobs.gdmArchive.Application: Starting Application on USCHDWNCN329V3B with PID 20056(C:\ IdeaProjects\ GdmArchive\ target\ classes started by *********** in C: \Users\ ***********\ IdeaProjects\ GdmArchive)
 2016 - 11 - 22 16: 49: 58.335 INFO 20056---[main] c.s.batch.jobs.gdmArchive.Application: No active profile set, falling back to default profiles: default
 2016 - 11 - 22 16: 49: 58.472 INFO 20056---[main] s.c.a.AnnotationConfigApplicationContext: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@ 4ae82894: startup date[Tue Nov 22 16: 49: 58 MST 2016]; root of context hierarchy
 2016 - 11 - 22 16: 49: 59.539 INFO 20056---[main] o.s.b.f.config.PropertiesFactoryBean: Loading properties file from URL[jar: file: /C:/Users / *********** / .m2 / repository / org / springframework / integration / spring - integration - core / 4.3.2.RELEASE / spring - integration - core - 4.3.2.RELEASE.jar!/META-INF/spring.integration.default.properties]
 2016 - 11 - 22 16: 49: 59.543 INFO 20056---[main] o.s.i.config.IntegrationRegistrar: No bean named 'integrationHeaderChannelRegistry' has been explicitly defined.Therefore, a default DefaultHeaderChannelRegistry will be created.
 2016 - 11 - 22 16: 49: 59.819 WARN 20056---[main] o.s.c.a.ConfigurationClassEnhancer: @Bean method ScopeConfiguration.stepScope is non - static and returns an object assignable to Spring  BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method'
 s declaring@ Configuration class.Add the 'static' modifier to this method to avoid these container lifecycle issues; see@ Bean javadoc for complete details.
 2016 - 11 - 22 16: 49: 59.834 WARN 20056---[main] o.s.c.a.ConfigurationClassEnhancer: @Bean method ScopeConfiguration.jobScope is non - static and returns an object assignable to Spring  BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method declaring@ Configuration class.Add the 'static' modifier to this method to avoid these container lifecycle issues; see@ Bean javadoc for complete details.
 2016 - 11 - 22 16: 49: 59.836 INFO 20056---[main] faultConfiguringBeanFactoryPostProcessor: No bean named 'errorChannel' has been explicitly defined.Therefore, a default PublishSubscribeChannel will be created.
 2016 - 11 - 22 16: 49: 59.845 INFO 20056---[main] faultConfiguringBeanFactoryPostProcessor: No bean named 'taskScheduler' has been explicitly defined.Therefore, a default ThreadPoolTaskScheduler will be created.
 2016 - 11 - 22 16: 50: 00.147 INFO 20056---[main] o.s.b.f.config.PropertiesFactoryBean: Loading properties file from URL[jar: file: /C:/Users / *********** / .m2 / repository / org / springframework / integration / spring - integration - core / 4.3.2.RELEASE / spring - integration - core - 4.3.2.RELEASE.jar!/META-INF/spring.integration.default.properties]
 2016 - 11 - 22 16: 50: 00.148 INFO 20056---[main] trationDelegate$BeanPostProcessorChecker: Bean 'integrationGlobalProperties' of type[class org.springframework.beans.factory.config.PropertiesFactoryBean] is not eligible for getting processed by all BeanPostProcessors(for example: not eligible for auto - proxying) 
 2016 - 11 - 22 16: 50: 00.163 INFO 20056---[main] trationDelegate$BeanPostProcessorChecker: Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration'
 of type[class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$85f858a4] is not eligible for getting processed by all BeanPostProcessors(for example: not eligible for auto - proxying)
 2016 - 11 - 22 16: 50: 00.221 INFO 20056---[main] trationDelegate$BeanPostProcessorChecker: Bean 'integrationGlobalProperties' of type[class java.util.Properties] is not eligible
 for getting processed by all BeanPostProcessors(for example: not eligible for auto - proxying)
 2016 - 11 - 22 16: 50: 00.353 WARN 20056---[main] s.c.a.AnnotationConfigApplicationContext: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'archiveJobConfig': Unsatisfied dependency expressed through field 'jobBuilderFactory';
 nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration': Unsatisfied dependency expressed through field 'dataSources';
 nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource[com / spring / batch / jobs / gdmArchive / InfrastructureConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate[javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: No supported DataSource type found
 2016 - 11 - 22 16: 50: 00.374 ERROR 20056---[main] o.s.boot.SpringApplication: Application startup failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'archiveJobConfig': Unsatisfied dependency expressed through field 'jobBuilderFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration': Unsatisfied dependency expressed through field 'dataSources'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource'
 defined in class path resource[com / spring / batch / jobs / gdmArchive / InfrastructureConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate[javax.sql.DataSource]: Factory method 'dataSource'
Run codeHide result

Job launch

t , , . .

@ComponentScan
@EnableAutoConfiguration
public class ArchiveJob {

   public int startJob(List paramList) throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, BeansException {

        SpringApplication app = new SpringApplication(ArchiveJob.class);
        ConfigurableApplicationContext ctx = app.run();

        BatchStatus exitStatus;
        String test = "2016";

        SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
        Job archiveDBJob = ctx.getBean("archiveDBJob", Job.class);


        JobParameters jobParameters = new JobParametersBuilder()
                .addString("year", test)
                .toJobParameters();

        JobExecution jobExecution = jobLauncher.run(archiveDBJob, jobParameters);
        exitStatus = jobExecution.getStatus();

        if(exitStatus.equals("COMPLETED"))
            return 1;
        else
            return 0;
   }


}
Hide result

ArchiveJobConfig

, Spring Batch java config. , , .. .

@Configuration
@EnableBatchProcessing
@Import( InfrastructureConfig.class )
public class ArchiveJobConfig {

    @Autowired
    public JobBuilderFactory jobBuilderFactory;

    @Autowired
    public StepBuilderFactory stepBuilderFactory;

    @Autowired
    public DataSource dataSource;

    @Bean
    public ItemReader<Person> reader() {
            FlatFileItemReader<Person> reader = new FlatFileItemReader<Person>();
            reader.setResource(new ClassPathResource("sample-data.csv"));
            reader.setLineMapper(new DefaultLineMapper<Person>() {{
                setLineTokenizer(new DelimitedLineTokenizer() {{
                    setNames(new String[] { "firstName", "lastName" });
                }});
                setFieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {{
                    setTargetType(Person.class);
                }});
            }});
            return reader;
    }

    @Bean
    public PersonItemProcessor processor() {
        return new PersonItemProcessor();
    }

    @Bean
    public ItemWriter<Person> writer() {
        JdbcBatchItemWriter<Person> writer = new JdbcBatchItemWriter<Person>();
        writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<Person>());
        writer.setSql("INSERT INTO people (first_name, last_name) VALUES (:firstName, :lastName)");
        writer.setDataSource(dataSource);
        return writer;
    }

    @Bean
    public Job archiveDBJob() {
        return jobBuilderFactory.get("archiveDBJob")
                .incrementer(new RunIdIncrementer())
                .flow(step1())
                .end()
                .build();
    }

    @Bean
    public Step step1() {
        return stepBuilderFactory.get("step")
                .<Person,Person>chunk(10)
                .reader(reader())
                .processor(processor())
                .writer(writer())
                .build();
    }
}
Hide result

- DataSource Bean

, , URL . . EnableBatchProcessing jobRepository bean, bean , . , , - . /

@Configuration
@PropertySource("classpath:spring/batch/config/db.properties")
public class InfrastructureConfig {

    @Autowired
    Environment env;

    @Bean
    public DataSource dataSource() {
        return DataSourceBuilder.create()
//              .driverClassName(env.getProperty("databaseUrl"))
//              .url(env.getProperty("databaseUrl"))
                .driverClassName("com.mysql.jdbc.Driver")
                .url("databaseUrl")
                .build();
    }
}
Hide result

::Spring Boot::(v1.3.5.RELEASE)

 2016 - 11 - 22 16: 49: 58.315 INFO 20056---[main] c.s.batch.jobs.gdmArchive.Application: Starting Application on USCHDWNCN329V3B with PID 20056(C:\ IdeaProjects\ GdmArchive\ target\ classes started by *********** in C: \Users\ ***********\ IdeaProjects\ GdmArchive)
 2016 - 11 - 22 16: 49: 58.335 INFO 20056---[main] c.s.batch.jobs.gdmArchive.Application: No active profile set, falling back to default profiles: default
 2016 - 11 - 22 16: 49: 58.472 INFO 20056---[main] s.c.a.AnnotationConfigApplicationContext: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@ 4ae82894: startup date[Tue Nov 22 16: 49: 58 MST 2016]; root of context hierarchy
 2016 - 11 - 22 16: 49: 59.539 INFO 20056---[main] o.s.b.f.config.PropertiesFactoryBean: Loading properties file from URL[jar: file: /C:/Users / *********** / .m2 / repository / org / springframework / integration / spring - integration - core / 4.3.2.RELEASE / spring - integration - core - 4.3.2.RELEASE.jar!/META-INF/spring.integration.default.properties]
 2016 - 11 - 22 16: 49: 59.543 INFO 20056---[main] o.s.i.config.IntegrationRegistrar: No bean named 'integrationHeaderChannelRegistry' has been explicitly defined.Therefore, a
 default DefaultHeaderChannelRegistry will be created.
 2016 - 11 - 22 16: 49: 59.819 WARN 20056---[main] o.s.c.a.ConfigurationClassEnhancer: @Bean method ScopeConfiguration.stepScope is non - static and returns an object assignable to Spring  BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method'
 s declaring@ Configuration class.Add the 'static' modifier to this method to avoid these container lifecycle issues; see@ Bean javadoc for complete details.
 2016 - 11 - 22 16: 49: 59.834 WARN 20056---[main] o.s.c.a.ConfigurationClassEnhancer: @Bean method ScopeConfiguration.jobScope is non - static and returns an object assignable to Spring  BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method declaring@ Configuration class.Add the 'static' modifier to this method to avoid these container lifecycle issues; see@ Bean javadoc for complete details.
 2016 - 11 - 22 16: 49: 59.836 INFO 20056---[main] faultConfiguringBeanFactoryPostProcessor: No bean named 'errorChannel' has been explicitly defined.Therefore, a default PublishSubscribeChannel will be created.
 2016 - 11 - 22 16: 49: 59.845 INFO 20056---[main] faultConfiguringBeanFactoryPostProcessor: No bean named 'taskScheduler' has been explicitly defined.Therefore, a default ThreadPoolTaskScheduler will be created.
 2016 - 11 - 22 16: 50: 00.147 INFO 20056---[main] o.s.b.f.config.PropertiesFactoryBean: Loading properties file from URL[jar: file: /C:/Users / *********** / .m2 / repository / org / springframework / integration / spring - integration - core / 4.3.2.RELEASE / spring - integration - core - 4.3.2.RELEASE.jar!/META-INF/spring.integration.default.properties]
 2016 - 11 - 22 16: 50: 00.148 INFO 20056---[main] trationDelegate$BeanPostProcessorChecker: Bean 'integrationGlobalProperties' of type[class org.springframework.beans.factory.config.PropertiesFactoryBean] is not eligible for getting processed by all BeanPostProcessors(for example: not eligible for auto - proxying) 
 2016 - 11 - 22 16: 50: 00.163 INFO 20056---[main] trationDelegate$BeanPostProcessorChecker: Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration'
 of type[class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$85f858a4] is not eligible for getting processed by all BeanPostProcessors(for example: not eligible for auto - proxying)
 2016 - 11 - 22 16: 50: 00.221 INFO 20056---[main] trationDelegate$BeanPostProcessorChecker: Bean 'integrationGlobalProperties' of type[class java.util.Properties] is not eligible
 for getting processed by all BeanPostProcessors(for example: not eligible for auto - proxying)
 2016 - 11 - 22 16: 50: 00.353 WARN 20056---[main] s.c.a.AnnotationConfigApplicationContext: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'archiveJobConfig': Unsatisfied dependency expressed through field 'jobBuilderFactory';
 nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration': Unsatisfied dependency expressed through field 'dataSources';
 nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource[com / spring / batch / jobs / gdmArchive / InfrastructureConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate[javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: No supported DataSource type found
 2016 - 11 - 22 16: 50: 00.374 ERROR 20056---[main] o.s.boot.SpringApplication: Application startup failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'archiveJobConfig': Unsatisfied dependency expressed through field 'jobBuilderFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration': Unsatisfied dependency expressed through field 'dataSources'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource'
 defined in class path resource[com / spring / batch / jobs / gdmArchive / InfrastructureConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate[javax.sql.DataSource]: Factory method 'dataSource'
Hide result
+4

Source: https://habr.com/ru/post/1661651/


All Articles