akka-http icon indicating copy to clipboard operation
akka-http copied to clipboard

HttpServerRoutingMinimal.scala the sample shown on the getting started page doesn't compile or startup

Open normana400 opened this issue 2 years ago • 1 comments

expected: the getting started code should work as coded

actual:

1: code doesn't compile (missing an import and declaration of an implicit materializer)

import scala.concurrent.ExecutionContext

implicit val materializer: ActorMaterializer = ActorMaterializer()

2: the scala code looks like an attempted translation of the java example (ie. top level class is implemented as a java main versus a scala App

3: after compiling, the example doesn't startup successfully (has an undecipherable runtime class not found error that triggers with the Http() invocation

Exception in thread "main" java.lang.NoClassDefFoundError: akka/stream/Attributes$CancellationStrategy$Strategy
	at ui.Main$.delayedEndpoint$ui$Main$1(Main.scala:38)
	at ui.Main$delayedInit$body.apply(Main.scala:14)
	at scala.Function0.apply$mcV$sp(Function0.scala:34)
	at scala.Function0.apply$mcV$sp$(Function0.scala:34)
	at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
	at scala.App.$anonfun$main$1$adapted(App.scala:76)
	at scala.collection.immutable.List.foreach(List.scala:389)
	at scala.App.main(App.scala:76)
	at scala.App.main$(App.scala:74)
	at ui.Main$.main(Main.scala:14)
	at ui.Main.main(Main.scala)
Caused by: java.lang.ClassNotFoundException: akka.stream.Attributes$CancellationStrategy$Strategy
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	... 11 more

normana400 avatar Mar 17 '22 22:03 normana400

1: code doesn't compile (missing an import and declaration of an implicit materializer)

Hmm, seems to work for me: https://github.com/raboof/akka-http-4077 . Can you spot what was the difference with your scenario?

2: the scala code looks like an attempted translation of the java example (ie. top level class is implemented as a java main versus a scala App

Would indeed be nicer as a scala App. Would you be interested in contributing that improvement?

3: after compiling, the example doesn't startup successfully (has an undecipherable runtime class not found error that triggers with the Http() invocation

This suggests you haven't introduced the akka-stream dependency yet. There's an example of this at https://doc.akka.io/docs/akka-http/current/introduction.html#using-akka-http but indeed it's easy to miss.

raboof avatar Mar 18 '22 16:03 raboof