2

I'm writing a Spring Boot application that uses Spring HATEOAS. When I want to use the EntityLinks object in the hateoas library - it's missing methods that should be available according to the docs. The method I'm trying to use is linkForSingleResource().

I'm guessing it's a dependency version issue. I looked at Migrating to Spring HATEOAS 1.0 and they have you download and run a script but it doesn't run.

Here's my pom file (I took some other dependencies to make it shorter):


<project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.0.M4</version>
        <relativePath /> 
    </parent>
    <dependency>
        <groupId>org.springframework.hateoas</groupId>
        <artifactId>spring-hateoas</artifactId>
        <version>2.2.0.M4</version>
    </dependency>
    <!-- Added starter-hateoas as @Gabriel suggested -->
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-hateoas</artifactId>
            <version>2.2.0.M4</version>
    </dependency>
    <repositories>
            <repository>
                <id>spring-snapshots</id>
                <name>Spring Snapshots</name>
                <url>https://repo.spring.io/snapshot</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>spring-milestones</id>
                <name>Spring Milestones</name>
                <url>https://repo.spring.io/milestone</url>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>spring-snapshots</id>
                <name>Spring Snapshots</name>
                <url>https://repo.spring.io/snapshot</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
            <pluginRepository>
                <id>spring-milestones</id>
                <name>Spring Milestones</name>
                <url>https://repo.spring.io/milestone</url>
            </pluginRepository>
        </pluginRepositories>



This is the stack trace:

Caused by: java.lang.ClassNotFoundException: org.springframework.hateoas.server.LinkRelationProvider
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_60]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_60]
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_60]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_60]
    ... 37 common frames omitted  

It's looking for the org.springframework.hateoas.server which doesn't exist in the 0.25.1.RELEASE according to the API docs.

mmera
  • 327
  • 5
  • 17
  • Did you try specifying a version on you `org.springframework.hateoas` dependency? Leaving the version field empty leaves dependency version management to Spring. If Spring is not managing it correctly, you should explicitly inform it. I dont know if this is the issue, but its worth the shot. – Gabriel Robaina Jul 22 '19 at 01:25
  • @GabrielPimenta - I did try that once. I specified the latest version `0.25.1.RELEASE` but it broke the rest of my dependencies and crashed the app. I found it at the [Maven Repository](https://mvnrepository.com/artifact/org.springframework.hateoas/spring-hateoas) – mmera Jul 22 '19 at 13:20
  • I did a quick search and noticed there is a starter-heateoas dependency out there... Take a look at https://stackoverflow.com/questions/55183478/how-do-i-include-the-spring-boot-hateoas-starter-which-contains-spring-hateoas-v , if it does not help, I will try to take a look when I get home. – Gabriel Robaina Jul 22 '19 at 13:41
  • @GabrielPimenta I updated the question but long story short it didn't work – mmera Jul 23 '19 at 03:05

1 Answers1

0

Not sure what I did right but this is the pom that ended up working (I did a combination of mvn tree, purge-local-repositories, clean install, and run)

 <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.6.RELEASE</version> <!-- changed this to 2.1.6 version -->
            <relativePath /> 
        </parent>   
    <build>
            <plugins>
    <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>2.2.0.M4</version> <!-- upgraded this -->
                </plugin>
        </plugins>
        </build>
    <dependencies>

            <dependency>
                <groupId>org.junit.jupiter</groupId> <!-- added this dependency-->
                <artifactId>junit-jupiter-api</artifactId>
                <version>5.5.1</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId> <!-- added this dependency-->
                <artifactId>spring-boot-starter-hateoas</artifactId>
                <version>2.2.0.M4</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.hateoas</groupId> 
                <artifactId>spring-hateoas</artifactId>
                <version>0.25.1.RELEASE</version>
            </dependency>
    </dependencies>
        <repositories>
            <repository>
                <id>spring-snapshots</id>
                <name>Spring Snapshots</name>
                <url>https://repo.spring.io/snapshot</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>spring-milestones</id>
                <name>Spring Milestones</name>
                <url>https://repo.spring.io/milestone</url>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>spring-snapshots</id>
                <name>Spring Snapshots</name>
                <url>https://repo.spring.io/snapshot</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
            <pluginRepository>
                <id>spring-milestones</id>
                <name>Spring Milestones</name>
                <url>https://repo.spring.io/milestone</url>
            </pluginRepository>
        </pluginRepositories>

Again I excluded some dependencies just to make it more concise but please let me know if you have questions.

mmera
  • 327
  • 5
  • 17