我有一个Spring Boot应用程序,它使用Spring Integration进行一些SFTP轮询......
我正在尝试按照此guide打包jar文件并将其作为war文件部署到wildfly 8.2应用程序服务器。我使用的gradle插件只允许部署war或ear文件。
因此,在我尝试完成此操作时,我使用嵌入式tomcat在本地运行,并且它可以正常运行,但是当我远程测试它时,应用程序已部署但从未启动过。
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Stasher extends SpringBootServletInitializer implements WebApplicationInitializer {
private static Class<Stasher> applicationClass = Stasher.class;
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
public static void main(String[] args) {
System.out.println("MAIN STARTED ***************************");
SpringApplication.run(Stasher.class, args);
}
}
来自Wildfly 8.2的日志
19:12:35,347 INFO [org.springframework.jmx.export.annotation.AnnotationMBeanExporter] (MSC service thread 1-4) Registering beans for JMX exposure on startup
19:12:35,352 INFO [org.springframework.context.support.DefaultLifecycleProcessor] (MSC service thread 1-4) Starting beans in phase -2147483648
19:12:35,353 INFO [org.springframework.context.support.DefaultLifecycleProcessor] (MSC service thread 1-4) Starting beans in phase 0
19:12:35,353 INFO [org.springframework.integration.endpoint.EventDrivenConsumer] (MSC service thread 1-4) Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
19:12:35,353 INFO [org.springframework.integration.channel.PublishSubscribeChannel] (MSC service thread 1-4) Channel 'Stasher-Default.errorChannel' has 1 subscriber(s).
19:12:35,353 INFO [org.springframework.integration.endpoint.EventDrivenConsumer] (MSC service thread 1-4) started _org.springframework.integration.errorLogger
19:12:35,359 INFO [org.springframework.boot.SpringApplication] (MSC service thread 1-4) Started application in 1.695 seconds (JVM running for 11619.131)
19:12:35,361 INFO [org.wildfly.extension.undertow] (MSC service thread 1-4) JBAS017534: Registered web context: /Stasher
19:12:35,439 INFO [org.jboss.as.server] (management-handler-thread - 1) JBAS018559: Deployed "Stasher.war" (runtime-name : "Stasher.war")
为什么在Wildfly中主要没有开始?!
答案 0 :(得分:1)
这是在app服务器中启动Spring Boot应用程序时使用的configure
方法。仅当您使用main
将应用程序作为可执行存档启动时,才会使用java -jar
方法。
答案 1 :(得分:0)
我删除了 SpringBootServletInitializer ,我的主要和配置方法的扩展,并添加了此方法。它现在开始了。
@Override
public void onStartup(ServletContext container) {
ApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/applicationContext.xml");
PollableChannel ftpChannel = context.getBean("ftpChannel", PollableChannel.class);
Message<?> message = ftpChannel.receive();
System.out.println("Received message: " + message);
}