christophknabe / spring-ddd-bank

A sample project following Domain Driven Design with Spring Data JPA
GNU Lesser General Public License v2.1
512 stars 125 forks source link

Make project compilable and runnable on Java 11 #18

Closed christophknabe closed 2 years ago

christophknabe commented 2 years ago

Mit AdoptOpenJDK 8 klappt ./mvnw clean test package.

christophknabe commented 2 years ago

Mit JAVA_HOME=AdoptOpenJDK11 versagt ./mvnw clean test package wie folgt: Execution default of goal org.codehaus.mojo:aspectj-maven-plugin:1.10:compile failed: Plugin org.codehaus.mojo:aspectj-maven-plugin:1.10 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:11.0.11 at specified path /home/knabe/.sdkman/candidates/java/11.0.11.hs-adpt/../lib/tools.jar

christophknabe commented 2 years ago

aspectj-maven-plugin upgraded to 1.14.0, aspectj.version upgraded to corresponding 1.9.7 ⇒ compilation works on JDK 11, but test execution fails with Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test failed: The forked VM terminated without properly saying goodbye. VM crash or System.exit called? Command was /bin/sh -c cd /home/knabe/hosted/github/spring-ddd-bank && /home/knabe/.sdkman/candidates/java/11.0.11.hs-adpt/bin/java -javaagent:/home/knabe/.m2/repository/org/jacoco/org.jacoco.agent/0.7.9/org.jacoco.agent-0.7.9-runtime.jar=destfile=/home/knabe/hosted/github/spring-ddd-bank/target/coverage-reports/jacoco-ut.exec -jar /home/knabe/hosted/github/spring-ddd-bank/target/surefire/surefirebooter14642211503071923056.jar /home/knabe/hosted/github/spring-ddd-bank/target/surefire/surefire5235105664614608974tmp /home/knabe/hosted/github/spring-ddd-bank/target/surefire/surefire_012601115383827369636tmp

christophknabe commented 2 years ago

Added a dependency for JAXB, as this is no longer part of JRE starting with Java 9. Now the test suite runs successfully, JaCoCo generates the Code Coverage report, and the server starts successfully. When browsing to http:://localhost:8080/ the entry page appears. When clicking on the link for "REST API Documentation", in the server log appears the following error:

2021-11-22 20:43:23.800 ERROR 544814 --- [nio-8080-exec-6] d.b.k.s.rest_interface.ExceptionAdvice   : Processing REST request threw exception:
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is ...
+Cause: java.lang.NoClassDefFoundError: com/sun/activation/registries/LogSupport
++Cause: java.lang.ClassNotFoundException: com.sun.activation.registries.LogSupport
----------Stack Trace follows:----------
++java.lang.ClassNotFoundException: com.sun.activation.registries.LogSupport
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
WAS CAUSING:
+java.lang.NoClassDefFoundError: com/sun/activation/registries/LogSupport
    at javax.activation.MimetypesFileTypeMap.<init>(MimetypesFileTypeMap.java:130)
    at javax.activation.FileTypeMap.getDefaultFileTypeMap(FileTypeMap.java:140)
    at org.springframework.web.accept.PathExtensionContentNegotiationStrategy$ActivationMediaTypeFactory.initFileTypeMap(PathExtensionContentNegotiationStrategy.java:210)
    at org.springframework.web.accept.PathExtensionContentNegotiationStrategy$ActivationMediaTypeFactory.<clinit>(PathExtensionContentNegotiationStrategy.java:176)
    at org.springframework.web.accept.PathExtensionContentNegotiationStrategy.handleNoMatch(PathExtensionContentNegotiationStrategy.java:130)
    at org.springframework.web.accept.ServletPathExtensionContentNegotiationStrategy.handleNoMatch(ServletPathExtensionContentNegotiationStrategy.java:78)
    at org.springframework.web.accept.AbstractMappingContentNegotiationStrategy.resolveMediaTypeKey(AbstractMappingContentNegotiationStrategy.java:78)
    at org.springframework.web.accept.AbstractMappingContentNegotiationStrategy.resolveMediaTypes(AbstractMappingContentNegotiationStrategy.java:61)
    at org.springframework.web.accept.ContentNegotiationManager.resolveMediaTypes(ContentNegotiationManager.java:125)
    at org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.getAcceptedMediaTypes(ProducesRequestCondition.java:261)
    at org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.getMatchingCondition(ProducesRequestCondition.java:194)
    at org.springframework.web.servlet.mvc.method.RequestMappingInfo.getMatchingCondition(RequestMappingInfo.java:214)
    at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getMatchingMapping(RequestMappingInfoHandlerMapping.java:94)
    at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getMatchingMapping(RequestMappingInfoHandlerMapping.java:58)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.addMatchingMappings(AbstractHandlerMethodMapping.java:380)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:347)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:314)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:61)
    at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:352)
    at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1131)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:936)
WAS CAUSING:
org.springframework.web.util.NestedServletException: Handler dispatch failed
...

The reason is, that the Java Activation Framework is no longer part of the JDK. Now the Spring Boot dependency should be upgraded to 2.1 in order to support Java 11 according to https://dzone.com/articles/migrating-springboot-applications-to-latest-java-v

christophknabe commented 2 years ago

Now with all set to Java 11 the following command run well: ./mvnw clean test package ./mvnw site:site But after importing the project into SpringTools 4 the test suite fails, as the repositories are not injected by compile-time weaving into the entity objects fetched from the database. The current state can be looked at in branch issue-18-on-java-11.

christophknabe commented 2 years ago

Done by PR #19