G
G
gsaw2021-08-19 16:49:25
Java
gsaw, 2021-08-19 16:49:25

How to properly configure a spring cloud application?

I can't configure spring batch application to run it in spring data flow. I've been fighting for two days now and everything is somehow very difficult.

The task is to read csv and write it to one plate. I configured the reader and writer, everything is simple here and it seems to work falsely. But all parsley, in spring batch and spring cloud task. They really need their own database in order to write down their control data TASK and JOB tables there. And all this greatly complicates the configuration of the application. To test locally, I created the following config

@Slf4j
@Configuration
@Profile("!cloud")
public class LocalConfiguration {

    @Bean
    public BatchConfigurer batchConfigurer(DataSource dataSource) {
        log.info("create local BatchConfigurer");
        return new DefaultBatchConfigurer(dataSource) {
            @Override
            public void setDataSource(DataSource dataSource) {
                log.info("called setDataSource");
            }
        };
    }

    @Bean
    public TaskConfigurer taskConfigurerLocal() {
        return new DefaultTaskConfigurer((DataSource) null);
    }
}


writer looks like this

@Bean
    public ItemWriter<ZgsEntity> writerProduction() {
        log.info("create writer");
        return new RepositoryItemWriter<ZgsEntity>() {{
            setRepository(zgsRepository);
        }};
    }


I start the application, like the csv file is being processed, hibernate queues the Entity for writing, but the writing itself does not occur. I see this in the log

2021-08-19 15:38:42.808 [main] TRACE o.h.engine.spi.IdentifierValue - ID unsaved-value strategy UNDEFINED
2021-08-19 15:38:42.808 [main] TRACE o.h.event.internal.EntityState - Transient instance of: com.daimler.zgs.entities.ZgsEntity
2021-08-19 15:38:42.808 [main] TRACE o.h.e.i.DefaultPersistEventListener - Saving transient instance
2021-08-19 15:38:42.808 [main] DEBUG o.h.e.i.AbstractSaveEventListener - Generated identifier: component[вырезал}, using strategy: org.hibernate.id.CompositeNestedGeneratedValueGenerator
2021-08-19 15:38:42.808 [main] TRACE o.h.e.i.AbstractSaveEventListener - Saving [com.daimler.zgs.entities.ZgsEntity#component[вырезал]{вырезал}]
2021-08-19 15:38:42.808 [main] TRACE org.hibernate.engine.spi.ActionQueue - Adding an EntityInsertAction for [com.daimler.zgs.entities.ZgsEntity] object
2021-08-19 15:38:42.808 [main] TRACE org.hibernate.engine.spi.ActionQueue - Adding insert with no non-nullable, transient entities: [EntityInsertAction[com.daimler.zgs.entities.ZgsEntity#[email protected]]]
2021-08-19 15:38:42.808 [main] TRACE org.hibernate.engine.spi.ActionQueue - Adding resolved non-early insert action.
2021-08-19 15:38:42.810 [main] TRACE org.hibernate.internal.SessionImpl - Closing session [0eb1b3ba-2fb0-4187-a618-0eb24fb56e8b]
2021-08-19 15:38:42.810 [main] TRACE o.h.e.j.internal.JdbcCoordinatorImpl - Closing JDBC container 
2021-08-19 15:38:42.810 [main] TRACE o.h.r.j.i.ResourceRegistryStandardImpl - Releasing JDBC resources
2021-08-19 15:38:42.810 [main] TRACE o.h.r.j.i.LogicalConnectionManagedImpl - Closing logical connection
2021-08-19 15:38:42.810 [main] TRACE o.h.r.j.i.LogicalConnectionManagedImpl - Logical connection closed
2021-08-19 15:38:42.811 [main] INFO  o.s.batch.core.step.AbstractStep - Step: [step1] executed in 48ms


I look in the application database, it's empty. Well, the logs show that he does not write anything. Where everything goes is not clear. Put on zgsRepository @Transactional, no use.

It seems to me that everything is written to the database, which is created under spring batch and spring cloud, although I specified @Primary for my DataSource.

The spring cloud and spring batch tutorials only hint at what needs to be done. And everything is so complicated. I'm already confused. Maybe there is some simple tutorial where both of these topics are chewed?

Thanks

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question