【问题标题】:Simple Spring REST service doesn't work简单的 Spring REST 服务不起作用
【发布时间】:2016-11-25 03:18:26
【问题描述】:

我正在尝试使用 Spring Boot 创建一个简单的 MongoDB REST 服务,但我一生都无法弄清楚为什么它如此难以启动。我在运行时使用 Gradle 编译了这些依赖项

compile('org.mongodb:bson:3.3.0')
compile 'org.mongodb:mongodb-driver:3.3.0'
compile('org.springframework.boot:spring-boot-starter-data-mongodb')
compile('springframework:spring-web:1.2.6')

应用程序提前退出并带有一些神秘的消息:

Closing org.springframework.context.annotation.AnnotationConfigApplicationContext

然后我尝试添加一些 更多 依赖项,看看是否有帮助...上帝,我有依赖项:

compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-tomcat")

这导致了一个更更多神秘的信息:

java.lang.NoSuchMethodError: org.springframework.web.context.support.ServletContextAwareProcessor: method <init>()V not found

我觉得启动这样一个简单的服务的过程非常复杂......我用 Express、Revel 和 Django 非常简单地完成了这个,但 Spring Boot 似乎并不容易。我在这个过程中缺少什么?

谢谢!

【问题讨论】:

  • 看起来你的类路径中有不兼容的 sping jar 版本。构造函数 ServletContextAwareProcessor() 是在 Spring 的第 4 版中引入的。请检查 spring-context.jar 的版本

标签: java spring tomcat gradle spring-boot


【解决方案1】:

删除

compile('springframework:spring-web:1.2.6')

来自您的 Gradle 文件。这件神器年代久远。 Spring Boot 依赖引入了所有必需的 Spring 依赖,因此通常不需要自己指定 Spring 依赖。

【讨论】:

  • 谢谢!下次我需要记住保持最新的依赖关系
  • @pward Spring 有一个项目生成器,它可以生成具有正确依赖关系的有保证的有效 Gradle 或 Maven 项目,因此您不必记住如何设置它:start.spring.io
猜你喜欢
  • 1970-01-01
  • 2020-01-21
  • 2015-10-24
  • 2017-02-09
  • 1970-01-01
  • 2018-04-22
  • 2016-11-16
  • 2015-05-26
  • 1970-01-01
相关资源
最近更新 更多