Reputation: 419
I'm just experimenting with Quarkus and I'm having a problem on the ResourceLoader. Specifically, when I try to use the ResourceLoader inject, the clean install by maven goes wrong
@Autowired
private ResourceLoader resourceLoader;
this is the maven output:
[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
Do you know how you can use the ResourceLoader in Quarkus, or if there is an equivalent way to read a file in the classpath's resources?
This is my current situation:
I have got the files in project resources folder and I would like to read them, for example in this way:
With Spring Boot I have no problem.
Thanks in advance for your time!
Upvotes: 1
Views: 6229
Reputation: 419
I solved it in the following way:
ClassLoader classLoader = getClass().getClassLoader();
try (InputStream is = classLoader.getResourceAsStream("domains/nations.json")) {
this.nations = mapper.readValue(is, Nations.class);
}
I then quit the ResourceLoader ;) thank you all
Upvotes: 3