|
17 | 17 |
|
18 | 18 | import org.slf4j.Logger;
|
19 | 19 | import org.slf4j.LoggerFactory;
|
| 20 | +import org.springframework.aot.hint.MemberCategory; |
20 | 21 | import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
|
21 | 22 | import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor;
|
22 | 23 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
23 | 24 | import org.springframework.modulith.core.util.ApplicationModulesExporter;
|
24 | 25 | import org.springframework.modulith.runtime.ApplicationModulesRuntime;
|
25 | 26 |
|
| 27 | +import com.jayway.jsonpath.internal.function.PathFunctionFactory; |
| 28 | + |
26 | 29 | /**
|
27 | 30 | * Renders the application module description JSON into a resource named
|
28 | 31 | * {@value ApplicationModulesExporter#DEFAULT_LOCATION}.
|
@@ -51,6 +54,22 @@ public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableL
|
51 | 54 |
|
52 | 55 | context.getRuntimeHints().resources().registerPattern(location);
|
53 | 56 | context.getGeneratedFiles().addResourceFile(location, exporter.toJson());
|
| 57 | + |
| 58 | + // Register JSONPath internals as available for reflective construction to be able to read the generated files in |
| 59 | + // a native image |
| 60 | + // |
| 61 | + // TODO: Remove once https://github.com/json-path/JsonPath/issues/1042 is fixed |
| 62 | + |
| 63 | + var reflection = context.getRuntimeHints().reflection(); |
| 64 | + var classLoader = ApplicationModulesFileGeneratingProcessor.class.getClassLoader(); |
| 65 | + |
| 66 | + PathFunctionFactory.FUNCTIONS.values().forEach(it -> { |
| 67 | + |
| 68 | + // Tweak name due to shading |
| 69 | + var typeName = it.getName().replace("com.jayway.jsonpath", "org.springframework.modulith.runtime.jsonpath"); |
| 70 | + |
| 71 | + reflection.registerTypeIfPresent(classLoader, typeName, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS); |
| 72 | + }); |
54 | 73 | };
|
55 | 74 | }
|
56 | 75 | }
|
0 commit comments