问题
Currently I am trying to migrate an API built in .NET to Java using Spring and it's related components. The only thing preventing me from completing this project is the lack of Affordances in the current release version of Spring HATEOAS (0.25.1), I am trying to replicate the data contracts as closely as I can in order to prevent breaking clients currently consuming the API.
Spring HATEOAS is included via the spring-boot-starter-hateoas Maven dependency.
I have tried the current build snapshot of the starter dependency but to no avail (the latest spring-hateos lib is not included in the starter build snapshot).
1) Is there a way to include the current milestone release into my project? If so, how do you recommend I do it.
2) If there is no way to do this, does anyone have any suggestions on how to add the Affordance concept to the current version? (Incurring some tech debt at this point is not a concern, so if you have an inelegant work around please share it, this will help me conceptually).
3) Would it be a better idea to create the HTTP return object as a HashMap and serialize it to JSON? (I understand that link of paths etc would need to be manually handled)
Other Versions: spring-boot-starter-parent: 2.1.3.RELEASE
Thanks
回答1:
Regarding question 1) Add the following dependency and do not forget that this one originates for now from the Spring Milestone Repository.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
<version>2.2.0.M1</version>
</dependency>
<repositories>
<repository>
<id>repository.spring.milestone</id>
<name>Spring Milestone Repository</name>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
Alternatively you could use the whole spring-boot-starter
in version 2.2.0.M1
which also contains spring-boot-starter-hateoas
in 1.0.0.M1
.
Question 2) should no longer concern you, question 1) seems to be easier solvable.
Regarding question 3) IMHO a strongly-typed (response-) object should almost everywhere be preferred as it makes your intentions more clear, is more easily maintainable and testable and sets you free from any worries about casting or implicit type-conversions and so on.
来源:https://stackoverflow.com/questions/55183478/how-do-i-include-the-spring-boot-hateoas-starter-which-contains-spring-hateoas-v