我只是在尝试Quarkus,而ResourceLoader出现了问题。具体来说,当我尝试使用ResourceLoader注入时,maven进行的全新安装出错了

@Autowired
private ResourceLoader resourceLoader;


这是Maven的输出:

[error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException:    javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type org.springframework.core.io.ResourceLoader and qualifiers [@Default]
[ERROR]     - java member: it.siae.pae.configurations.service.DomainsManager#resourceLoader
[ERROR]     - declared on CLASS bean [types=[it.siae.pae.configurations.service.DomainsManager, java.lang.Object], qualifiers=[@Default, @Any], target=it.siae.pae.configurations.service.DomainsManager]
[ERROR]     at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:850)
[ERROR]     at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:220)
[ERROR]     at io.quarkus.arc.processor.BeanProcessor.initialize(BeanProcessor.java:106)
[ERROR]     at io.quarkus.arc.deployment.ArcProcessor.validate(ArcProcessor.java:251)
[ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]     at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR]     at io.quarkus.deployment.ExtensionLoader$1.execute(ExtensionLoader.java:941)
[ERROR]     at io.quarkus.builder.BuildContext.run(BuildContext.java:415)
[ERROR]     at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
[ERROR]     at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2011)
[ERROR]     at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1535)
[ERROR]     at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1426)
[ERROR]     at java.lang.Thread.run(Thread.java:748)
[ERROR]     at org.jboss.threads.JBossThread.run(JBossThread.java:479)
[ERROR] Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type org.springframework.core.io.ResourceLoader and qualifiers [@Default]
[ERROR]     - java member: it.siae.pae.configurations.service.DomainsManager#resourceLoader
[ERROR]     - declared on CLASS bean [types=[it.siae.pae.configurations.service.DomainsManager, java.lang.Object], qualifiers=[@Default, @Any], target=it.siae.pae.configurations.service.DomainsManager]
[ERROR]     at io.quarkus.arc.processor.Beans.resolveInjectionPoint(Beans.java:472)
[ERROR]     at io.quarkus.arc.processor.BeanInfo.init(BeanInfo.java:404)
[ERROR]     at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:212)
[ERROR]     ... 14 more


您知道如何在Quarkus中使用ResourceLoader,或者是否有等效的方法读取类路径资源中的文件吗?

这是我目前的情况:

java - 在Quarkus中使用ResourceLoader-LMLPHP

我已经在项目资源文件夹中找到了文件,我想以这种方式读取它们:

java - 在Quarkus中使用ResourceLoader-LMLPHP

使用Spring Boot我没有问题。

在此先感谢您的时间!

最佳答案

我通过以下方式解决了它:

ClassLoader classLoader = getClass().getClassLoader();

    try (InputStream is = classLoader.getResourceAsStream("domains/nations.json")) {
        this.nations = mapper.readValue(is, Nations.class);
    }


然后我退出ResourceLoader;)谢谢大家

09-10 20:24