gpt4 book ai didi

java - Micronaut 列出资源文件

转载 作者:行者123 更新时间:2023-12-02 01:22:09 26 4
gpt4 key购买 nike

在 Spring 我可以使用ResourceLoaderResourcePatternUtils:

class Foobar {
private ResourceLoader resourceLoader;

@Autowired
public Foobar(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}

Resource[] loadResources(String pattern) throws IOException {
return ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources(pattern);
}
}

并使用它

Resource[] resources = foobar.loadResources("classpath*:../../dir/*.txt");

我如何在 Micronaut 中做到这一点?

我找到了一个解决方案 Is there an equivalent for Springs Resource in Micronaut?

添加

    @Inject
private DefaultClassPathResourceLoader resourceLoader;

...
Stream<URL> currencyStream = resourceLoader.getResources("currency/*.json");
long count = currencyStream.count();
...

但计数始终为 0 =(

最佳答案

检查PathMatchingResourcePatternResolver来自 io.micronaut.cli.io.support;

关于java - Micronaut 列出资源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57510886/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com