小编the*_*ddy的帖子

如何读取存储在 Spring Webflux 类路径资源中的 JSON 文件?

我是 Spring WebFlux 的新手。我想读取存储在其中的 JSON 文件classpath resource并将其转换为 POJO 类。文件夹结构是resources/defaults/myjson.json. 我正在使用 Jackson 进行转换。阅读后,这将转换为MyJson.java. 截至目前,我正在执行以下方法。

@Service
public class MyService {

    private final ObjectMapper objectMapper;
    private MyJson myJson;

    @Autowired
    public MyService(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
        this.myJson = MyFileUtils.readFile(objectMapper, "classpath:/defaults/myjson.json", MyJson.class);
    }

    public MyJson getMyJson() {
        return this.myJson;
    }
}
Run Code Online (Sandbox Code Playgroud)

有没有其他办法?

spring-boot spring-webflux

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

如何在不使用Thymeleaf或其他模板引擎的情况下处理Spring Boot中的Whitelabel 404错误

我有一个带有 React JS 客户端的 Spring Boot + Spring Security 应用程序。我想在其中有一个自定义样式的 404 错误页面,而不使用 Thymeleaf。

我的Spring Boot版本是2.0.0.M2

war文件结构是

root-dir
|- WEB-INF
|   |- lib
|   |- classes
|   |   |- static
|   |   |   |- * (react dist)
|   |   |- * (other files)
|- org
|- META-INF
Run Code Online (Sandbox Code Playgroud)

我的 war 文件构建过程如下。

  1. 使用 Gradle npm 插件构建 ReactJS 发行版
  2. Gradle 任务将把发行版复制到staticwar 目录中
  3. 最终建立战争

请帮我解决这个问题。

java spring reactjs spring-boot

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

标签 统计

spring-boot ×2

java ×1

reactjs ×1

spring ×1

spring-webflux ×1