【发布时间】:2017-01-20 08:02:00
【问题描述】:
我正在学习 Spring,但遇到了问题。我创建了在嵌入式 servlet 容器中运行的独立应用程序(Web 服务)。我将 Intellij IDEA 与 gradle 一起使用。当我从 IDEA 运行应用程序时 - 一切正常。但是当我创建了 jar 文件并通过控制台运行时(“java -jar my.jar”),我遇到了错误(如下)。 我正在加载官方示例(https://github.com/spring-guides/gs-rest-service),但它也不起作用(通过运行 jar)。 我看到了这个链接,但它没有帮助我:Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean
请帮忙
错误日志:
18:47:26.079 [main] ERROR o.s.boot.SpringApplication - Application startup faile
d org.springframework.context.ApplicationContextException: Unable to start embedde
d container; nested exception is org.springframework.context.ApplicationContextE
xception: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedS
ervletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationConte
xt.onRefresh(EmbeddedWebApplicationContext.java:135) ~[ClientsIm.jar:na]
at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:476) ~[ClientsIm.jar:na]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationConte
xt.refresh(EmbeddedWebApplicationContext.java:120) ~[ClientsIm.jar:na]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.
java:691) [ClientsIm.jar:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java
:320) [ClientsIm.jar:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java
:952) [ClientsIm.jar:na]
at com.clientsim.server.Application.main(Application.java:13) [ClientsIm
.jar:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to st
art EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory
bean.
我的 build.gradle:
group 'ClientsIm'
version '1.0-SNAPSHOT'
buildscript {
repositories {
maven { url "http://repo.spring.io/libs-release" }
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
sourceCompatibility = 1.5
repositories {
maven { url "http://repo.spring.io/libs-release" }
mavenLocal()
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile group: 'junit', name: 'junit', version: '4.11'
}
【问题讨论】:
-
使用 Gradle 构建 jar 时正在运行什么命令?
标签: java spring web-services spring-boot