Я столкнулся с проблемой, что не могу добавить маршрут в контекст весны.Я пытался сделать это:
@SpringBootApplication
class TestApp
fun main(args: Array<String>) {
runApplication<TestApp>(*args) {
addInitializers(beans {
bean {
RoutesConfig().router()
}
})
}
}
, и мой маршрут
@Configuration
class RoutesConfig {
fun router() = router {
GET("/health") { _ -> ServerResponse.ok().body(BodyInserters.fromObject("OK")) }
}
}
Я пытался добавить аннотацию @Bean
, пробовал через SpringApplication.run()
, пробовал через различные варианты конфигурации, включаяBeanInitializers
- ничего не работает.Что я делаю не так?
2019-05-21 21:17:04.752 INFO 7785 --- [ main] c.p.i.s.manager.TestAppKt : No active profile set, falling back to default profiles: default
2019-05-21 21:17:05.333 INFO 7785 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-05-21 21:17:05.345 INFO 7785 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-05-21 21:17:05.345 INFO 7785 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.12
2019-05-21 21:17:05.349 INFO 7785 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/adm/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2019-05-21 21:17:05.404 INFO 7785 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-05-21 21:17:05.404 INFO 7785 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 630 ms
2019-05-21 21:17:05.420 INFO 7785 --- [ main] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2019-05-21 21:17:05.423 INFO 7785 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-05-21 21:17:05.423 INFO 7785 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-05-21 21:17:05.423 INFO 7785 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'formContentFilter' to: [/*]
2019-05-21 21:17:05.423 INFO 7785 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2019-05-21 21:17:05.568 INFO 7785 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-05-21 21:17:05.733 WARN 7785 --- [ main] reactor.netty.tcp.TcpResources : [http] resources will use the default LoopResources: DefaultLoopResources {prefix=reactor-http, daemon=true, selectCount=12, workerCount=12}
2019-05-21 21:17:05.734 WARN 7785 --- [ main] reactor.netty.tcp.TcpResources : [http] resources will use the default ConnectionProvider: PooledConnectionProvider {name=http, poolFactory=reactor.netty.resources.ConnectionProvider$$Lambda$378/429639728@4d8286c4}
2019-05-21 21:17:05.841 INFO 7785 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-05-21 21:17:05.844 INFO 7785 --- [ main] c.p.i.s.manager.TestAppKt : Started TestAppKt in 1.495 seconds (JVM running for 2.14)