对于包含代码的Spark-java(与Spring Boot一起使用)
public static void main(String[] args) {
Spark.port(8080);
Spark.webSocket("/chat", ChatWebSocketHandler.class);
Spark.init();
我得到例外并停止
Exception in thread "Thread-2" java.lang.NoClassDefFoundError: org/eclipse/jetty/websocket/server/pathmap/PathSpec
at spark.embeddedserver.jetty.EmbeddedJettyServer.ignite(EmbeddedJettyServer.java:105)
at spark.Service.lambda$init$0(Service.java:349)
at spark.Service$$Lambda$7/1663488386.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.websocket.server.pathmap.PathSpec
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 4 more
使用Maven我使用
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5</version>
</dependency>
我知道了
jetty-server-9.3.11.v20160721.jar
,
websocket-server-9.3.11.v20160721.jar
以及其他许多依赖项
答案 0 :(得分:3)
问题是Spring Boot重新定义了要使用的更新的Jetty版本。
解决方案
<properties>
...
<jetty.version>9.3.6.v20151106</jetty.version> <!-- redefine for sparkjava 2.5 vs 9.3.11.v20160721 in spring-boot-dependencies -->
</properties>