-
Notifications
You must be signed in to change notification settings - Fork 583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hateoas Links are not deserialized in Spring Boot Native applications #5924
Comments
Here are some background information: We are currently using the following dependency in one of our task application we want to native compile with Spring Boot Native: <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dataflow-rest-client</artifactId>
</dependency we also added <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> because we saw that the To customize the DataFlowTemplate we are using the following code: RestTemplate prepareRestTemplate = DataFlowTemplate.prepareRestTemplate(restTemplateBuilder.build());
// Here we are going to apply a ClientHttpRequestInterceptor to get the a bearer from our OAuth Server and a RetryTemplate for retry behavior
return new DataFlowTemplate(new URI(customUriToOurSCDFBackend), prepareRestTemplate, null); To retrieve the
As of https://docs.spring.io/spring-hateoas/docs/current/reference/html/#client.rest-template the As we are using /**
* Configuration class for hateoas.
*/
@Configuration
@EnableConfigurationProperties(HateoasProperties.class)
@EnableHypermediaSupport(type = {
EnableHypermediaSupport.HypermediaType.HAL
})
public class SerialLauncherHateaosConfiguration {
/**
* Gets the hal configuration.
*
* @return the hal configuration
*/
@Bean
public HalConfiguration applicationJsonHalConfiguration() {
return new HalConfiguration().withMediaType(MediaType.APPLICATION_JSON);
}
} The spring-boot-maven-plugin also shows it during process-aot at build time
In addition to that all scdf classes are not registered for reflections, because it is a Spring Boot 2 dependency. So we are using a
Note: To enable all reflection access ways we are using The this.aboutOperations = new AboutTemplate(restTemplate, resourceSupport.getLink(AboutTemplate.ABOUT_REL).get()); To me this looks like the I think that this will also occur when you port the DataFlowTemplate to Spring Boot 3 without refactoring the code / providing specific native image hints. It has only to be a small thing to be adjusted to make this work 😃 and it would be great if you could help even if this might not be supported out of the box. |
Hey @cppwfs / @onobc / @corneil
/**
* Generates hints of the used classes for the native build.
*/
@Configuration
@ImportRuntimeHints(SerialLauncherRuntimeHints.class)
@Slf4j
public class SpringCloudDataFlowRestRuntimeHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
Arrays.stream(System.getProperty("java.class.path").split(File.pathSeparator)).forEach(classpathEntry -> {
// If the classpathEntry is no jar skip it
if (!classpathEntry.endsWith(".jar")) {
return;
}
try (JarInputStream is = new JarInputStream(Files.newInputStream(Path.of(classpathEntry)))) {
JarEntry entry = is.getNextJarEntry();
while (entry != null) {
String entryName = entry.getName();
if (entryName.endsWith(".class")
&& !entryName.contains("package-info")
&& entryName.startsWith("org/springframework/cloud/dataflow/rest")
) {
String scdfResourceClassName = entryName.replace("/", ".");
String scdfResourceClassNameWithoutClass = scdfResourceClassName.substring(0, scdfResourceClassName.length() - 6);
log.info("Registered class {} for reflections and serialization.", scdfResourceClassNameWithoutClass);
hints.reflection().registerType(TypeReference.of(scdfResourceClassNameWithoutClass), MemberCategory.values());
hints.serialization().registerType(TypeReference.of(scdfResourceClassNameWithoutClass));
}
entry = is.getNextJarEntry();
}
} catch (IOException e) {
log.warn("Error while reading jars", e);
}
});
}
}
/**
* Configuration class for hateoas. See <a href="https://stackoverflow.com/questions/56352544/how-to-ensure-application-haljson-is-the-first-supported-media-type">hal+json issue</a>
*/
@Configuration
@EnableConfigurationProperties(HateoasProperties.class)
@Import(RepositoryRestMvcConfiguration.class)
public class SerialLauncherHateaosConfiguration {
/**
* Gets the hal configuration.
*
* @return the hal configuration
*/
@Bean
public HalConfiguration applicationJsonHalConfiguration() {
return new HalConfiguration().withMediaType(MediaType.APPLICATION_JSON);
}
}
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dataflow-rest-client</artifactId>
<!-- Excluded because we don't need JPA / Hibernate / Skipper for Rest-Calls -->
<exclusions>
<exclusion>
<artifactId>spring-data-jpa</artifactId>
<groupId>org.springframework.data</groupId>
</exclusion>
<exclusion>
<artifactId>hibernate-core</artifactId>
<groupId>org.hibernate</groupId>
</exclusion>
<exclusion>
<artifactId>spring-cloud-skipper</artifactId>
<groupId>org.springframework.cloud</groupId>
</exclusion>
<!-- TODO SCDF 3.x Remove this exculsion if scdf is updated -->
<exclusion>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
</dependency>
SCDF Rest Client of version 2.11.x is working this way with Spring Boot 3 native images I think beside the registration of the package this is still an Spring Hateoas issue, because it does not take |
Description:
This is a followup issue on spring-projects/spring-hateoas#2210.
Release versions:
2.11.x
Custom apps:
N/A
Steps to reproduce:
Screenshots:
N/A
Additional context:
I am going to research a bit more when I converted all other task application of us to native-images, but it would be great if you could tell me which classes required to be included for reflect-config.json in addition to the mentioned classes/packages here: spring-projects/spring-hateoas#2210 (comment)
The text was updated successfully, but these errors were encountered: