Wildfly 未启动可部署的 war 文件

Wildfly not starting a deployable war file

我有一个 Spring 启动应用程序,它使用 Spring 集成来做一些 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 中 main 没有启动?!

这是在应用程序服务器中启动 Spring 启动应用程序时使用的 configure 方法。 main 方法仅在您使用 java -jar.

作为可执行存档启动应用程序时使用

我删除了 SpringBootServletInitializer 的扩展,我的 mainconfigure 方法并添加了这个方法代替。它现在启动了。

@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);
}