Introduce RuntimeHintsUtils.registerResourceIfNecessary
This commit introduces a new registerResourceIfNecessary() method in RuntimeHintsUtils that simplifies the registration of hints for `classpath:` resources. Closes gh-29083
This commit is contained in:
@@ -19,11 +19,14 @@ package org.springframework.aot.hint.support;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.ResourceHints;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.TypeHint;
|
||||
import org.springframework.aot.hint.TypeHint.Builder;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.core.annotation.MergedAnnotation;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* Utility methods for runtime hints support code.
|
||||
@@ -92,4 +95,18 @@ public abstract class RuntimeHintsUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the supplied resource is a {@link ClassPathResource} that
|
||||
* {@linkplain Resource#exists() exists} and register the resource for run-time
|
||||
* availability accordingly.
|
||||
* @param hints the {@link RuntimeHints} instance to use
|
||||
* @param resource the resource to register
|
||||
* @see ResourceHints#registerPattern(String)
|
||||
*/
|
||||
public static void registerResourceIfNecessary(RuntimeHints hints, Resource resource) {
|
||||
if (resource instanceof ClassPathResource classPathResource && classPathResource.exists()) {
|
||||
hints.resources().registerPattern(classPathResource.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user