小编Jul*_*nen的帖子

在 Hibernate 中使用 Spring boot 配置的 Jackson Objectmapper

我想将 Hibernate 配置为使用 Spring 创建的 JacksonObjectmapper在 json 和实体之间进行映射。在我正在从事的项目中,我已经将 Jooq 配置为使用 Spring ObjectMapper,但我在如何配置 Hibernate 以使用它方面遇到了麻烦。最终的目标是 Jooq 和 Hibernate 都将使用相同的ObjectMapper是 Jooq 和 Hibernate 都使用相同的.

我查了弗拉德的这篇文章。不幸的是,本文中给出的所有提示不适用于我正在从事的项目。

这是我尝试过的示例配置

@Configuration
public class HibernateConfiguration implements HibernatePropertiesCustomizer {
    //Autowire Objectmapper created by Spring
    @Autowired
    ObjectMapper objectMapper;

    @Override
    public void customize(Map<String, Object> hibernateProperties) {
        ObjectMapperSupplier objectMapperSupplier = () -> objectMapper;
        // Below config doesn't work since Hibernate types creates it's own mapper
        hibernateProperties.put("hibernate.types.jackson.object.mapper", objectMapperSupplier);
}
Run Code Online (Sandbox Code Playgroud)

还尝试了相同的方法,将 Objectmapper 添加到 hibernate-types.properties …

java spring hibernate spring-boot hibernate-types

12
推荐指数
2
解决办法
7743
查看次数

Vaadin 在 StreamResource 回调方法中缺少 SpringSecurityContext

我得到了一个简单的 StreamResource 示例,其中 SpringSecurityContext 在单击下载锚点时神秘消失。基本上,当单击下载锚点时,createInputStream会调用方法来创建下载文件,但是当执行此方法时,SecurityContext 为空。下面是重现该问题的简化示例。

public class HomeView extends VerticalLayout {

public HomeView() {
    Anchor anchor = new Anchor();
    anchor.add("DOWNLOAD");
    anchor.setHref(new StreamResource("file", () -> createInputStream()));
    add(anchor);
    // SecurityContext returns correct value and is not null.
    System.err.println(SecurityContextHolder.getContext());
    System.err.println("Thread name in constructor : " + Thread.currentThread().getName());
}

private InputStream createInputStream() {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
        outputStream.write("text".getBytes());
    } catch (IOException e) {
        e.printStackTrace();
    }
    // SecurityContextHolder.getContext() returns null here. Why?
    System.err.println(SecurityContextHolder.getContext());
    System.err.println("Thread name in createInputStream() : " …
Run Code Online (Sandbox Code Playgroud)

java spring-security vaadin spring-boot vaadin-flow

5
推荐指数
1
解决办法
358
查看次数