【发布时间】:2017-11-22 03:23:10
【问题描述】:
我们决定将 SparkJava、Kotlin 和 Mustache 用于商业 web 产品。我们的产品需要与 Google (YouTube) API 集成。
项目的所有端点都正常工作。 (后台、CRUD 操作等)我们开始实现 YouTube 的集成,我不得不将 Google 库添加到我的项目中以启动。 (不添加任何额外代码,只是添加了库 google-oauth-client-jetty。)
您可以在下面找到我的 Gradle 库:
dependencies {
// Below library is a part of the requirements or YouTube Integration
compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.11.0-beta'
// And these are the others
compile fileTree(include: ['*.jar'], dir: 'lib')
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile group: 'com.sparkjava', name: 'spark-core', version: '2.7.0'
compile 'com.google.code.gson:gson:2.8.1'
compile group: 'commons-codec', name: 'commons-codec', version: '1.9'
compile 'com.github.jkcclemens:khttp:0.1.0' // -SNAPSHOT
compile 'com.beust:klaxon:0.30'
compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.58'
compile group: 'org.hibernate', name: 'hibernate-gradle-plugin', version: '5.2.10.Final'
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.10.Final'
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.2.10.Final'
compile group: 'org.hibernate', name: 'hibernate-validator', version: '6.0.0.CR3'
compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'
compile group: 'org.hibernate', name: 'hibernate-c3p0', version: '4.1.0.Final'
compile 'io.sentry:sentry-log4j:1.4.0'
compile group: 'javax.mail', name: 'mail', version: '1.4.1'
compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.0'
compile group: 'commons-validator', name: 'commons-validator', version: '1.4.0'
compile "org.testng:testng:6.9.10"
compile "org.apache.httpcomponents:httpclient:4.5.2"
compile "org.apache.httpcomponents:httpcore:4.4.4"
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
compile group: 'com.sparkjava', name: 'spark-template-mustache', version: '2.5.5'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
当我特别将库 'google-oauth-client-jetty', version: '1.11.0-beta' 添加到项目中时,我无法通过 http(GET、POST、一个都不放)。我启用了 SparkJava 的日志,我正面临下面的日志。
比如我在打电话
结果是:
[qtp1864334028-15] WARN org.eclipse.jetty.server.HttpChannel - /admin
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getHeaders(Ljava/lang/String;)Ljava/util/Collection;
at spark.utils.GzipUtils.checkAndWrap(GzipUtils.java:67)
at spark.http.matching.Body.serializeTo(Body.java:69)
at spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:189)
at spark.embeddedserver.jetty.JettyHandler.doHandle(JettyHandler.java:50)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1568)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:564)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:317)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)
at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:126)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:745)
看起来,在 google-oauth-client-jetty 库中使用方法“LocalServerReceiver()”是非常必要的。
我们需要任何帮助才能继续前进。
【问题讨论】:
-
你需要分析你的传递依赖,看起来你添加的新库引入了不同版本的servlet库。运行
gradle dependencies以查看您的依赖关系树(添加新的 dep 之前和之后)。 -
另外,请尝试
gradle dependencyInsight解释here
标签: java kotlin google-oauth google-api-java-client spark-java