在扩展具有台阶的mongoItemReader时,所有字段都充满空值,但是如果使用mongoItemReader,则一切都可以

发布于 2025-02-02 13:48:44 字数 1359 浏览 4 评论 0原文

我正在与MongoDB数据库一起在春季批处理中使用本地分区。 我创建了一个扩展MongoItemReader的订阅程序。

    public class SubscriptionReader<T>  extends MongoItemReader<T> implements InitializingBean {
private MongoOperations template;
private Query query;
private String queryString;

    // and other private fields with setter methods and custom implementation of DoPageRead method.

这是JobConfig类:

    @Configuration
    @EnableBatchProcessing
    public class JobConfig

{
...

        @Bean
        @StepScope
        public SubscriptionReader<Subscription> reader()
        {
            Map<String, Sort.Direction> sorts = new HashMap<>();
            sorts.put("_id", Sort.Direction.ASC);
            SubscriptionReader<Subscription> reader = new SubscriptionReader<>();
                    reader.setCollection("subscription");
                    reader.setQuery(query(null, null, null));

                    reader.setTemplate(template);
                    reader.setName("reader");
                    reader.setTargetType(Subscription.class);
                    reader.setPageSize(20000000);
    return reader;
        }

如果我用MongoItemReader替换订阅者,一切都可以,但是当Spring创建分区步骤时,所有字段的订阅程序都是无效的。 编辑: 当我的课程呼叫的后propertiesset方法并检查无效性时,我会得到异常。如果我删除它,我将获得一个NullPoInterException。 预先感谢您的时间和关注。

I'm using local partitioning in the spring batch along with the MongoDb database.
I created a SubscriptionReader that extends MongoItemReader.

    public class SubscriptionReader<T>  extends MongoItemReader<T> implements InitializingBean {
private MongoOperations template;
private Query query;
private String queryString;

    // and other private fields with setter methods and custom implementation of DoPageRead method.

This is JobConfig class:

    @Configuration
    @EnableBatchProcessing
    public class JobConfig

{
...

        @Bean
        @StepScope
        public SubscriptionReader<Subscription> reader()
        {
            Map<String, Sort.Direction> sorts = new HashMap<>();
            sorts.put("_id", Sort.Direction.ASC);
            SubscriptionReader<Subscription> reader = new SubscriptionReader<>();
                    reader.setCollection("subscription");
                    reader.setQuery(query(null, null, null));

                    reader.setTemplate(template);
                    reader.setName("reader");
                    reader.setTargetType(Subscription.class);
                    reader.setPageSize(20000000);
    return reader;
        }

If I replace SubscriptionReader with MongoItemReader, everything is ok but all fields of SubscriptionReader are null when spring creates partitioned steps.
Edit:
I get exception when afterPropertiesSet method of my class calls and it checks for nullability. If I remove that, I'll get a nullPointerException.
Thanks in advance for your time and attention.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文