instrumenting-java-apps-using-opentelemetry icon indicating copy to clipboard operation
instrumenting-java-apps-using-opentelemetry copied to clipboard

Support for Java 11

Open bartland opened this issue 2 years ago • 0 comments

Thank you for this outstanding tutorial.

I am restricted to Java 11 for now. To do this I made simple updates to 2 files: pom.xml and HelloAppController.java.

pom.xml

Replace 17 with 11.

           <maven.compiler.release>11</maven.compiler.release>
           :
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <release>${maven.compiler.release}</release>
                </configuration>
            </plugin>

HelloAppController.java

Replace private record Response (String message) {...}

with

    public class Response {
        String message;
        public Response(String message) {
            Objects.requireNonNull(message);
            this.message = message;
        }
        public boolean isValid() {
            return true;
        }
        public String getMessage() { return this.message; }

      @Override
      public boolean equals(Object obj) {
        if (obj == this) return true;
        if (obj == null || obj.getClass() != this.getClass()) return false;
        Response that = (Response) obj;
        return this.message == that.message;
      }

      @Override
      public int hashCode() {
        return Objects.hash(message);
      }

      @Override
      public String toString() {
        return this.message;
      }
    }

bartland avatar Jun 14 '23 01:06 bartland