Java 带有嵌入式servlet容器的Spring应用程序运行错误
我正在学习春天,我有一个问题。我创建了独立的应用程序(web服务),它在嵌入式servlet容器中运行。我使用Intellij IDEA和gradle。当我从IDEA运行应用程序时,一切正常。但当我创建了jar文件并通过控制台(“java-jar my.jar”)运行时,我出现了错误(如下)。 我加载了官方示例(),但它也不起作用(通过运行jar)。 我看到了这个链接,但它对我没有帮助: 请帮忙 错误日志:Java 带有嵌入式servlet容器的Spring应用程序运行错误,java,spring,web-services,spring-boot,Java,Spring,Web Services,Spring Boot,我正在学习春天,我有一个问题。我创建了独立的应用程序(web服务),它在嵌入式servlet容器中运行。我使用Intellij IDEA和gradle。当我从IDEA运行应用程序时,一切正常。但当我创建了jar文件并通过控制台(“java-jar my.jar”)运行时,我出现了错误(如下)。 我加载了官方示例(),但它也不起作用(通过运行jar)。 我看到了这个链接,但它对我没有帮助: 请帮忙 错误日志: 18:47:26.079 [main] ERROR o.s.boot.SpringApp
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.
我的身材。格雷德尔:
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创建你的罐子?也许你是从intellij导出的 (1) 使用gradle构建: 您应该使用gradle构建jar(使用
springbootgradle插件创建jar
)。在项目根目录下打开终端,然后键入:
$ gradle build
...
$ cd build/libs
$ java -jar yourjar.jar
(2) 从Intellij导出spring引导jar:
springbootgradle插件创建jar
)。在项目根目录下打开终端,然后键入:
$ gradle build
...
$ cd build/libs
$ java -jar yourjar.jar
(2) 从Intellij导出spring引导jar: