Spring 弹簧靴不';不要等待请求
昨天我有一种奇怪的春装行为 例如:我试图使用Spring 弹簧靴不';不要等待请求,spring,spring-boot,Spring,Spring Boot,昨天我有一种奇怪的春装行为 例如:我试图使用/gradlew bootRun启动服务器: ... :findMainClass :bootRun :: Spring Boot :: (v1.3.1.RELEASE) 2016-01-19 16:37:15.315 INFO 6118 --- [ main] c.e.server.Application$Companion : Starting Application.Companion
/gradlew bootRun
启动服务器:
...
:findMainClass
:bootRun
:: Spring Boot :: (v1.3.1.RELEASE)
2016-01-19 16:37:15.315 INFO 6118 --- [ main] c.e.server.Application$Companion : Starting Application.Companion on fake with PID 6118 (/home/user/code/xproject/server/build/classes/main started by user in /home/user/code/xproject/server)
2016-01-19 16:37:15.320 INFO 6118 --- [ main] c.e.server.Application$Companion : No active profile set, falling back to default profiles: default
2016-01-19 16:37:15.400 INFO 6118 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@a3ec6b: startup date [Tue Jan 19 16:37:15 GMT 2016]; root of context hierarchy
2016-01-19 16:37:17.908 INFO 6118 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-01-19 16:37:17.923 INFO 6118 --- [ main] c.e.server.Application$Companion : Started Application.Companion in 3.048 seconds (JVM running for 3.421)
2016-01-19 16:37:17.924 INFO 6118 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@a3ec6b: startup date [Tue Jan 19 16:37:15 GMT 2016]; root of context hierarchy
2016-01-19 16:37:17.930 INFO 6118 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
BUILD SUCCESSFUL
Total time: 23.756 secs
所以它不像以前那样等待请求。我认为类路径有一些问题,所以我在控制器和服务中放置了几个带注释的方法@PostConstruct,并可以确认它们被调用,所有依赖项都被注入
这是我的gradle.build:
buildscript {
ext.kotlin_version = '1.0.0-beta-4584'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'kotlin'
jar {
baseName = 'xproject'
version = '0.1.0'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-tomcat")
compile("org.springframework.boot:spring-boot-devtools")
compile 'org.springframework.data:spring-data-mongodb:1.8.2.RELEASE'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "com.restfb:restfb:1.18.1"
testCompile("junit:junit")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
sourceSets {
main {
java.srcDirs += ['java', 'kotlin']
}
test {
java.srcDirs += 'test'
}
}
UPD#1
这是应用程序类(我从一开始就没碰过)
给了我几乎相同的结果
:: Spring Boot :: (v1.3.1.RELEASE)
2016-01-19 17:18:19.790 INFO 8230 --- [ restartedMain] hello.GreetingController : Starting GreetingController on fake with PID 8230 (/home/user/code/xproject/server/build/classes/main started by user in /home/user/code/xproject/server)
2016-01-19 17:18:19.814 INFO 8230 --- [ restartedMain] hello.GreetingController : No active profile set, falling back to default profiles: default
2016-01-19 17:18:19.918 INFO 8230 --- [ restartedMain] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@71ceb8: startup date [Tue Jan 19 17:18:19 GMT 2016]; root of context hierarchy
!! Post construct called
2016-01-19 17:18:22.860 INFO 8230 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2016-01-19 17:18:22.905 INFO 8230 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-01-19 17:18:22.922 INFO 8230 --- [ restartedMain] hello.GreetingController : Started GreetingController in 4.022 seconds (JVM running for 4.949)
2016-01-19 17:18:22.924 INFO 8230 --- [ Thread-8] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@71ceb8: startup date [Tue Jan 19 17:18:19 GMT 2016]; root of context hierarchy
2016-01-19 17:18:22.930 INFO 8230 --- [ Thread-8] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
Process finished with exit code 1
我遇到了与您刚才描述的完全相同的问题,在我的例子中,我忘记添加SpringBootStarterWeb作为依赖项。我从一个只有SpringBootStarter的基本示例中复制/粘贴了依赖项,但我误读了它。 一旦我添加了它,容器就正常启动了,我得到了一个在8080端口监听的常规web应用程序 这是我的第一个非常基本的测试,所以它只有spring boot starter web、kotlin stdlib和kotlin reflect作为依赖项和类,如下所示:
@SpringBootApplication
class Application {
private val log = LoggerFactory.getLogger(Application::class.java)
}
fun main(args: Array<String>) {
SpringApplication.run(Application::class.java, *args)
}
@springboot应用程序
班级申请{
private val log=LoggerFactory.getLogger(应用程序::class.java)
}
趣味主线(args:Array){
run(Application::class.java,*args)
}
从我在代码中看到的情况来看,我唯一能想到的是,您可能也需要kotlin reflect。我从中得到了包含它的想法,并且使用它来。。。
祝你好运 请显示您的“应用程序”或“Application.Companion”类。@dunni我已更新了问题您的路径不知何故被阻塞了,它没有检测到tomcat,因此不会启动web应用程序,否则它会立即结束。(它应该启动一个Web内容,而不是一个简单的上下文。请确保没有任何东西改变Web内容。@M.Deinum我真的不知道如何检查它。我看到java启动时在类路径中指定了大量库。我也尝试了不同版本的gradle-运气不好
:: Spring Boot :: (v1.3.1.RELEASE)
2016-01-19 17:18:19.790 INFO 8230 --- [ restartedMain] hello.GreetingController : Starting GreetingController on fake with PID 8230 (/home/user/code/xproject/server/build/classes/main started by user in /home/user/code/xproject/server)
2016-01-19 17:18:19.814 INFO 8230 --- [ restartedMain] hello.GreetingController : No active profile set, falling back to default profiles: default
2016-01-19 17:18:19.918 INFO 8230 --- [ restartedMain] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@71ceb8: startup date [Tue Jan 19 17:18:19 GMT 2016]; root of context hierarchy
!! Post construct called
2016-01-19 17:18:22.860 INFO 8230 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2016-01-19 17:18:22.905 INFO 8230 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-01-19 17:18:22.922 INFO 8230 --- [ restartedMain] hello.GreetingController : Started GreetingController in 4.022 seconds (JVM running for 4.949)
2016-01-19 17:18:22.924 INFO 8230 --- [ Thread-8] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@71ceb8: startup date [Tue Jan 19 17:18:19 GMT 2016]; root of context hierarchy
2016-01-19 17:18:22.930 INFO 8230 --- [ Thread-8] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
Process finished with exit code 1
@SpringBootApplication
class Application {
private val log = LoggerFactory.getLogger(Application::class.java)
}
fun main(args: Array<String>) {
SpringApplication.run(Application::class.java, *args)
}