如何使用Jobrepository中的Spring-boot配置并获得的JDBCTEMPLATE?
HIHO,
我们在Spring-Boot 2.6.7服务中使用Spring Batch 4.3.5。到目前为止,所有事情都可以正常工作。在测试用例时,我们意识到batchautoconfiguration/batchconfigurerconfiguration创建了一个Jobrepository。这个工作需要的需要,需要一些JDBCoperations。因为在初始化所有bean时,没有从春季应用程序上下文中获取JDBCoperations的实例,所以JobReRepositoryFactoryBean决定创建一个类型的JDBCTEMPLATE的新实例并将其附加到JobReRepository。
因此,我想询问是否有可能附加Spring-Boot提供的JDBCTEMPLATE实例的“简单”?覆盖整个初始化机制是否还有另一种可能性?我们需要提供自己的批评家吗?
任何帮助都非常感谢! :)
Hiho,
we use Spring-Batch 4.3.5 inside a Spring-Boot 2.6.7 service. All things work fine so far. While unit testing the use-cases, we realized that the BatchAutoConfiguration/BatchConfigurerConfiguration creates a JobRepository. This JobRepository needs and wants some JdbcOperations. Because no instance of JdbcOperations is taken from the Spring application context while initializing all the beans, the JobRepositoryFactoryBean decides to create a fresh instance of type JdbcTemplate and attach it to the JobRepository.
Therefore I would like to ask if there is an 'easy' possibility to attach the instance of the JdbcTemplate that is provided by Spring-Boot? Is there another possibility as overwriting the whole initialization mechanism? Do we need to provide our own BatchConfigurer?
Any help is really appreciated! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那是不可能的。您需要提供一个自定义
batchConfigurer
,并使用boot启动的任何bean自动配置来配置您的作业存储库。这是一个快速示例:在此片段中,
dataSource
和jdbctemplate
作为参数传递给batchconfigurer
方法将是由boot自动配置的方法(并自动由春季自动)。That is not possible. You need to provide a custom
BatchConfigurer
and use any bean auto-configured by Boot to configure your job repository. Here is a quick example:In this snippet, the
dataSource
andjdbcTemplate
passed as parameters to thebatchConfigurer
method will be those auto-configured by Boot (and autowired by Spring).