鉴于代码,我试图弄清楚为什么我的spring boot应用程序会停止:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@Configuration
@EnableIntegration
public class FirestoreCommandIntegrationFlow {
@Bean
public StandardIntegrationFlow registerInboundAdapter() {
return IntegrationFlows.from("input")
.transform("hello"::equals)
.handle(m -> System.err.println("work"))
.get();
}
}
我试图弄清楚的是,为什么应用程序只是停止而没有任何错误,它正常启动,然后几秒钟后,它只是将订阅删除到“输入”通道并关闭流程。 我知道这可能是一个愚蠢的问题,但我只是找不到应用程序停止的原因。我一直遵循https://github.com/spring-projects/spring-integration-java-dsl/wiki/Spring-Integration-Java-DSL-Reference,据我所知,我的流程应继续监听“输入”通道,并且流程应继续运行。
注意:我的springboot应用程序已在application.properties中用spring.main.web-environment=false
禁用了Web服务器
日志:
2019-01-09 13:32:21.261 INFO 12658 --- [ main] c.r.t.m.Application : Starting Application on ...
2019-01-09 13:32:21.265 INFO 12658 --- [ main] c.r.t.m.Application : No active profile set, falling back to default profiles: default
2019-01-09 13:32:21.348 INFO 12658 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@625732: startup date [Wed Jan 09 13:32:21 CET 2019]; root of context hierarchy
2019-01-09 13:32:21.744 INFO 12658 --- [ main] o.s.i.c.IntegrationRegistrar : No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
2019-01-09 13:32:22.025 INFO 12658 --- [ main] faultConfiguringBeanFactoryPostProcessor : No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
2019-01-09 13:32:22.030 INFO 12658 --- [ main] faultConfiguringBeanFactoryPostProcessor : No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
2019-01-09 13:32:22.199 INFO 12658 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.integration.config.IntegrationManagementConfiguration' of type [org.springframework.integration.config.IntegrationManagementConfiguration$$EnhancerBySpringCGLIB$$b59005e8] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-01-09 13:32:22.446 INFO 12658 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'taskScheduler'
2019-01-09 13:32:22.854 INFO 12658 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2019-01-09 13:32:22.863 INFO 12658 --- [ main] o.s.c.s.DefaultLifecycleProcessor : Starting beans in phase 0
2019-01-09 13:32:22.863 INFO 12658 --- [ main] o.s.i.e.EventDrivenConsumer : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2019-01-09 13:32:22.863 INFO 12658 --- [ main] o.s.i.c.PublishSubscribeChannel : Channel 'application.errorChannel' has 1 subscriber(s).
2019-01-09 13:32:22.864 INFO 12658 --- [ main] o.s.i.e.EventDrivenConsumer : started _org.springframework.integration.errorLogger
2019-01-09 13:32:22.864 INFO 12658 --- [ main] o.s.i.e.EventDrivenConsumer : Adding {transformer} as a subscriber to the 'input' channel
2019-01-09 13:32:22.864 INFO 12658 --- [ main] o.s.i.c.DirectChannel : Channel 'application.input' has 1 subscriber(s).
2019-01-09 13:32:22.864 INFO 12658 --- [ main] o.s.i.e.EventDrivenConsumer : started org.springframework.integration.config.ConsumerEndpointFactoryBean#0
2019-01-09 13:32:22.872 INFO 12658 --- [ main] c.r.t.m.Application : Started Application in 2.032 seconds (JVM running for 2.652)
2019-01-09 13:32:22.874 INFO 12658 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@625732: startup date [Wed Jan 09 13:32:21 CET 2019]; root of context hierarchy
2019-01-09 13:32:22.876 INFO 12658 --- [ Thread-2] o.s.c.s.DefaultLifecycleProcessor : Stopping beans in phase 0
2019-01-09 13:32:22.877 INFO 12658 --- [ Thread-2] o.s.i.e.EventDrivenConsumer : Removing {transformer} as a subscriber to the 'input' channel
2019-01-09 13:32:22.877 INFO 12658 --- [ Thread-2] o.s.i.c.DirectChannel : Channel 'application.input' has 0 subscriber(s).
2019-01-09 13:32:22.877 INFO 12658 --- [ Thread-2] o.s.i.e.EventDrivenConsumer : stopped org.springframework.integration.config.ConsumerEndpointFactoryBean#0
2019-01-09 13:32:22.877 INFO 12658 --- [ Thread-2] o.s.i.e.EventDrivenConsumer : Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2019-01-09 13:32:22.877 INFO 12658 --- [ Thread-2] o.s.i.c.PublishSubscribeChannel : Channel 'application.errorChannel' has 0 subscriber(s).
2019-01-09 13:32:22.877 INFO 12658 --- [ Thread-2] o.s.i.e.EventDrivenConsumer : stopped _org.springframework.integration.errorLogger
2019-01-09 13:32:22.878 INFO 12658 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2019-01-09 13:32:22.878 INFO 12658 --- [ Thread-2] o.s.s.c.ThreadPoolTaskScheduler : Shutting down ExecutorService 'taskScheduler'
Process finished with exit code 0
答案 0 :(得分:2)
您的流量无所作为;它是静态的,并且自己不执行任何操作;它没有动态组件(轮询器,消息驱动的适配器);它需要一些东西来在线程上向它发送数据;例如主线程或其他一些非守护进程线程。
例如
@Bean
public ApplicationRunner runner(MessageChannel input) {
return args -> {
while (true) {
input.send(someMessage);
Thread.sleep(1_000);
}
}
}
这将在启动后在主线程上运行。
答案 1 :(得分:0)
如果您不是Web应用程序,但仍希望继续侦听/定期运行。尝试添加注释
@EnableScheduling
或
@计划的
到您的主应用程序或一些示例任务运行器
@EnableScheduling(initialDelay = 100, fixedRate = 100)public void run(){System.out.println("debug print time -->" + Calendar.getInstance().getTime());}
这也可以应用于SpringApplication上下文。