Spring native - 运行本机图像时具有多对多关系的查询不显示数据

问题描述

我在 webflux 服务中工作,该服务从 postgresql 数据库获取信息。当我从 Intellij Idea 运行它时,该服务运行良好。但是,当我生成本机图像时,一些响应数据是空的(我认为这是由于 jackson 中的一些配置错误,但我无法修复它)。有人可以帮忙吗?

这是我拥有的存储库:

@Repository
public interface BookAuthorsRepository extends ReactiveCrudRepository<BookAuthors,Long> {

    @Query("SELECT b.id,b.title,b.description," +
            "( SELECT json_agg(json_build_object('authorId',a.id,'fullName',concat_ws(' ',a.name,a.surname))) " +
            "  FROM authors a JOIN books_authors ba ON a.id=ba.author_id " +
            "  WHERE b.id=ba.book_id ) as authors" +
            "  FROM books b")
    Flux<BookAuthors> findAll();

    @Query("SELECT b.id,a.surname))) " +
            "  FROM authors a JOIN books_authors ba ON a.id=ba.author_id " +
            "  WHERE b.id=ba.book_id ) as authors" +
            "  FROM books b " +
            "  WHERE b.id=:bookId" )
    Mono<BookAuthors> findByBookId(final Long bookId);
}

我还有一个转换器,它基本上返回 BookAuthors 对象:

public class BookAuthorsReadConverter implements Converter<Row,BookAuthors> {
    private static Logger LOG = LoggerFactory.getLogger(BookAuthorsReadConverter.class);

    @Override
    public BookAuthors convert(Row row) {
        final Long id = row.get("id",Long.class);
        final String bookTitle = row.get("title",String.class);
        final String bookDescription = row.get("description",String.class);

        final List<AuthorRef> authors = new java.util.ArrayList<>();

        final JSONArray array = new JSONArray(row.get("authors",String.class));
        array.forEach(item -> {
                    final JSONObject jsonObject = (JSONObject) item;
                    final AuthorRef authorRef = new AuthorRef(Long.parseLong(jsonObject.get("authorId").toString()),jsonObject.get("fullName").toString());
                    authors.add(authorRef);
                }
        );

        LOG.info("Book with authors: {}",new BookAuthors(id,bookTitle,bookDescription,authors));
        return new BookAuthors(id,authors);
    }
}

回复中我得到了这个:

{
    "id": 2,"title": "Hands-On Spring Security 5 for Reactive Applications","description": "Learn effective ways to secure your applications with Spring and Spring WebFlux (English Edition)","authors": [
        {}
    ]
}

我什么时候应该得到这个:

{
    "id": 2,"authors": [
        {
            "authorId": 2,"fullName": "Tomcy John"
        }
    ]
}
```

Do anyone kNow what's going on in the native image? What am I missing? Please help.

Thank you very much in advance.
Best regards.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)