在 Quarkus 上运行以下代码:
@Singleton
@RegisterForReflection
public class StoreService {
private static final Logger LOGGER = Logger.getLogger(StoreService.class);
@Inject
@RestClient
StoresApiClient client;
@CacheResult(cacheName = "stores")
@Fallback(fallbackMethod = "allFallbackStores")
public List<Store> allStores() {
// call REST API using client
}
@SuppressWarnings("unused")
public List<Store> allFallbackStores() {
try {
LOGGER.info("Falling back to internal stores list");
...
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
回退机制在常规 JDK 模式下正常工作。另一方面,在本机图像模式下,@Fallback
注释不被尊重,并且在 API 调用不成功后引发异常。@RegisterForReflection
如果注释到位,可能是什么原因?