gpt4 book ai didi

java - 使用 aws lambda native 读取文本文件

转载 作者:行者123 更新时间:2023-12-01 16:21:59 25 4
gpt4 key购买 nike

我有一个 quarkus lambda,需要读取几个文本文件。这在制作非 native 版本时效果很好。但是,当我尝试使用 native 版本时,如果找不到文件。我已将文本文件添加到资源和 resources/META-INF.resources 文件夹中,但没有成功。

加载它们的类是

@Component
public class ModulusWeightTableSupplier implements Supplier<List<ModulusWeightTableEntry>>{

private static final String MODULUS_WEIGHT_TABLE = "/AccountModulus_Weight_Table.txt";

@Override
public List<ModulusWeightTableEntry> get(){

final List<ModulusWeightTableEntry> modulusWeightTable = new ArrayList<>();
try(final BufferedReader br = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(MODULUS_WEIGHT_TABLE)))){
String line;
while ((line = br.readLine()) != null) {
final String[] fields = line.split("\\s+");
modulusWeightTable.add(new ModulusWeightTableEntry(fields));
}
}
catch (final IOException e) {
throw new TableSupplierRuntimeException("An error occurred loading the modulus weight table or sort code substitution table", e);
}
return modulusWeightTable;
}
}

由于某种原因, native 版本找不到这些文件。我想我缺少一些告诉它包含资源文件夹的东西?现在,在使用 native 版本时,它使用自定义运行时。

2020-06-07 13:15:21,940 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-1) HTTP Request to /bank-details-validation/v1/account-validation failed, error id: fcffa89d-efaa-4a26-859d-031cfb3ddbaf-1: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:106)
at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:372)
at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:216)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:515)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:259)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:160)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:362)
at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:163)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:245)
at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:123)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.access$000(VertxRequestHandler.java:36)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler$1.run(VertxRequestHandler.java:87)
at io.quarkus.runtime.CleanableExecutor$CleaningRunnable.run(CleanableExecutor.java:231)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
at java.base/java.lang.Thread.run(Thread.java:830)
at org.jboss.threads.JBossThread.run(JBossThread.java:479)
Caused by: java.lang.NullPointerException
at java.base/java.io.Reader.<init>(Reader.java:167)
at java.base/java.io.InputStreamReader.<init>(InputStreamReader.java:72)
at bankdetailsvalidator.quarkus.supplier.ModulusWeightTableSupplier.get(ModulusWeightTableSupplier.java:32)

最佳答案

如果您要添加外部资源,则需要将它们包含到 native 镜像中。除非您明确告知,否则 native 镜像不包含资源。

在最新的 Quarkus 版本中,您可以使用:

quarkus.native.resources.includes = AccountModulus_Weight_Table.txt

甚至:

quarkus.native.resources.includes = *.txt

或(带有 glob 的**/*.txt)

在旧版本中,您必须执行以下操作:https://quarkus.io/guides/writing-native-applications-tips#including-resources .

关于java - 使用 aws lambda native 读取文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62245795/

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