Springboot Wildfly 10.0 War 文件部署 ---> 无法实例化 WebApplicationInitializer class

Springboot Wildfly 10.0 War file deployment ---> Failed to instantiate WebApplicationInitializer class

我使用 scala Rest api 创建了 spring 启动,它正在使用 tomcat(默认服务器)和 jar 文件。现在我想部署到 Jboss/Wildfly 10.0 并创建 war 文件。在部署期间,我遇到以下问题。有人可以帮助解决这个问题吗?

POM 文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.aexp.prospect</groupId>
    <artifactId>atules</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <!--packaging>jar</packaging -->

    <name>atules</name>
    <url>http://maven.apache.org</url>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath />
        <!-- lookup parent from repository -->
    </parent>

    <!-- properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
        </properties -->

    <properties>
        <start-class>com.aexp.prospect.atules.AtulApplication</start-class>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <!-- dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> 
        <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies -->

    <dependencies>

        <!-- Additional for war files -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>

        <!-- dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> 
            </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> 
            </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> 
            </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> 
            </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> 
            </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> 
            </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> 
            <scope>test</scope> </dependency> <dependency> <groupId>io.springfox</groupId> 
            <artifactId>springfox-swagger2</artifactId> <version>2.4.0</version> </dependency> 
            <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> 
            <version>2.4.0</version> </dependency -->

        <!-- dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-library</artifactId> 
            <version>2.11.8</version> </dependency -->
        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.5</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/net.liftweb/lift-json -->
        <dependency>
            <groupId>net.liftweb</groupId>
            <artifactId>lift-json_2.11</artifactId>
            <version>2.6.3</version>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!-- Additional for war files -->

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
        </dependency>


    </dependencies>
    <build>
        <finalName>SpringBootES</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <!-- build> <plugins> <plugin> <groupId>net.alchim31.maven</groupId> <artifactId>scala-maven-plugin</artifactId> 
        <version>3.1.3</version> <executions> <execution> <goals> <goal>compile</goal> 
        <goal>testCompile</goal> </goals> </execution> </executions> </plugin> <plugin> 
        <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> 
        </plugin> </plugins> </build -->

</project>

部署时出现错误消息:

13:56:38,104 INFO  [org.jboss.as.repository] (DeploymentScanner-threads - 2) WFLYDR0001: Content added at location C:\Risk_Mgt\Downloads\wildfly-10.0.0.Final\standalone\data\contentdbc0aa1700b71ef90ada1bc3c326e8d02776\content
13:56:38,109 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0019: Stopped Driver service with driver-name = SpringBootES.war_org.h2.Driver_1_4
13:56:38,119 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 249) WFLYUT0022: Unregistered web context: /SpringBootES
13:56:38,126 INFO  [io.undertow.servlet] (ServerService Thread Pool -- 249) Closing Spring root WebApplicationContext
13:56:38,127 INFO  [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext] (ServerService Thread Pool -- 249) Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@42447031: startup date [Wed Mar 21 13:30:53 EDT 2018]; root of context hierarchy
13:56:38,129 INFO  [org.springframework.jmx.export.annotation.AnnotationMBeanExporter] (ServerService Thread Pool -- 249) Unregistering JMX-exposed beans on shutdown
13:56:40,019 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0028: Stopped deployment SpringBootES.war (runtime-name: SpringBootES.war) in 1913ms
13:56:40,023 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0027: Starting deployment of "SpringBootES.war" (runtime-name: "SpringBootES.war")
13:56:51,926 WARN  [org.jboss.as.ee] (MSC service thread 1-2) WFLYEE0007: Not installing optional component org.springframework.http.server.ServletServerHttpAsyncRequestControl due to an exception (enable DEBUG log level to see the cause)
13:56:51,928 WARN  [org.jboss.as.ee] (MSC service thread 1-2) WFLYEE0007: Not installing optional component org.springframework.web.context.request.async.StandardServletAsyncWebRequest due to an exception (enable DEBUG log level to see the cause)
13:56:52,006 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.4)
13:56:52,012 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0018: Started Driver service with driver-name = SpringBootES.war_org.h2.Driver_1_4
13:56:52,093 INFO  [io.undertow.servlet] (ServerService Thread Pool -- 260) 2 Spring WebApplicationInitializers detected on classpath
13:56:53,033 INFO  [stdout] (ServerService Thread Pool -- 260) 

13:56:53,033 INFO  [stdout] (ServerService Thread Pool -- 260)   .   ____          _            __ _ _

13:56:53,034 INFO  [stdout] (ServerService Thread Pool -- 260)  /\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \

13:56:53,034 INFO  [stdout] (ServerService Thread Pool -- 260) ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \

13:56:53,034 INFO  [stdout] (ServerService Thread Pool -- 260)  \/  ___)| |_)| | | | | || (_| |  ) ) ) )

13:56:53,034 INFO  [stdout] (ServerService Thread Pool -- 260)   '  |____| .__|_| |_|_| |_\__, | / / / /

13:56:53,035 INFO  [stdout] (ServerService Thread Pool -- 260)  =========|_|==============|___/=/_/_/_/

13:56:53,055 INFO  [stdout] (ServerService Thread Pool -- 260)  :: Spring Boot ::        (v1.5.2.RELEASE)

13:56:53,056 INFO  [stdout] (ServerService Thread Pool -- 260) 

13:56:53,241 INFO  [com.aexp.prospect.atules.AtulApplication] (ServerService Thread Pool -- 260) Starting AtulApplication on NYKPC06712N with PID 16880 (started by pveerana in C:\Risk_Mgt\Downloads\wildfly-10.0.0.Final\bin)
13:56:53,241 INFO  [com.aexp.prospect.atules.AtulApplication] (ServerService Thread Pool -- 260) No active profile set, falling back to default profiles: default
13:56:53,304 INFO  [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext] (ServerService Thread Pool -- 260) Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@61eb59d6: startup date [Wed Mar 21 13:56:53 EDT 2018]; root of context hierarchy
13:56:55,604 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService Thread Pool -- 260) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
13:56:55,877 INFO  [io.undertow.servlet] (ServerService Thread Pool -- 260) Initializing Spring embedded WebApplicationContext
13:56:55,878 INFO  [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 260) Root WebApplicationContext: initialization completed in 2573 ms
13:56:57,166 INFO  [org.springframework.boot.web.servlet.ServletRegistrationBean] (ServerService Thread Pool -- 260) Mapping servlet: 'dispatcherServlet' to [/]
13:56:57,168 INFO  [org.springframework.boot.web.servlet.FilterRegistrationBean] (ServerService Thread Pool -- 260) Mapping filter: 'errorPageFilter' to: [/*]
13:56:57,168 INFO  [org.springframework.boot.web.servlet.FilterRegistrationBean] (ServerService Thread Pool -- 260) Mapping filter: 'characterEncodingFilter' to: [/*]
13:56:57,168 INFO  [org.springframework.boot.web.servlet.FilterRegistrationBean] (ServerService Thread Pool -- 260) Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
13:56:57,168 INFO  [org.springframework.boot.web.servlet.FilterRegistrationBean] (ServerService Thread Pool -- 260) Mapping filter: 'httpPutFormContentFilter' to: [/*]
13:56:57,168 INFO  [org.springframework.boot.web.servlet.FilterRegistrationBean] (ServerService Thread Pool -- 260) Mapping filter: 'requestContextFilter' to: [/*]
13:56:58,042 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] (ServerService Thread Pool -- 260) Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@61eb59d6: startup date [Wed Mar 21 13:56:53 EDT 2018]; root of context hierarchy
13:56:58,226 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (ServerService Thread Pool -- 260) Mapped "{[/api/eshost/{eshost}/indexName/{indexName}/_basicSearch],methods=[GET]}" onto public java.lang.String com.aexp.prospect.atules.controllers.AtulSearchController.basicSearch(java.lang.String,java.lang.String,java.lang.String,java.lang.String)
13:56:58,235 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (ServerService Thread Pool -- 260) Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
13:56:58,235 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (ServerService Thread Pool -- 260) Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
13:56:58,306 INFO  [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] (ServerService Thread Pool -- 260) Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
13:56:58,306 INFO  [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] (ServerService Thread Pool -- 260) Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
13:56:58,503 INFO  [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] (ServerService Thread Pool -- 260) Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
13:56:58,924 INFO  [org.springframework.jmx.export.annotation.AnnotationMBeanExporter] (ServerService Thread Pool -- 260) Registering beans for JMX exposure on startup
13:56:58,988 INFO  [com.aexp.prospect.atules.AtulApplication] (ServerService Thread Pool -- 260) Started AtulApplication in 6.67 seconds (JVM running for 50698.335)
13:56:58,994 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 260) Initializing Mojarra 2.2.12-jbossorg-2 20150729-1131 for context '/SpringBootES'
13:57:03,889 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 260) WFLYUT0021: Registered web context: /SpringBootES
13:57:03,975 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0016: Replaced deployment "SpringBootES.war" with deployment "SpringBootES.war"
13:57:03,976 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) WFLYCTL0183: Service status report
WFLYCTL0186:   Services which failed to start:      service jboss.undertow.deployment.default-server.default-host."/atules-0.0.1-SNAPSHOT": org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host."/atules-0.0.1-SNAPSHOT": java.lang.RuntimeException: javax.servlet.ServletException: Failed to instantiate WebApplicationInitializer class

13:57:03,986 INFO  [org.jboss.as.repository] (DeploymentScanner-threads - 2) WFLYDR0002: Content removed from location C:\Risk_Mgt\Downloads\wildfly-10.0.0.Final\standalone\data\content\e46fce1370fb5d7b11d99012c33f8a30730b2a\content

问题出在 POM 文件上,我已修复它。下面是我使用的 POM 文件。尤其是start-class、spring-boot-maven-plugin和servlet(最初我开发的是Application,应该转成servlet)。这些在我最初的 POM 文件中不存在。还应排除 tomcat 作为 Jboss/Wildfly 10.0

中的此部署

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.aexp.xxx</groupId>
<artifactId>xxxes</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>xxxes</name>
<url>http://maven.apache.org</url>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.2.RELEASE</version>
    <relativePath />
    <!-- lookup parent from repository -->
</parent>

<properties>
    <start-class>com.aexp.xxx.xxxes.<Application Class Name></start-class>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>


    <!-- https://mvnrepository.com/artifact/log4j/log4j -->
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <scope>provided</scope>
    </dependency>

</dependencies>
<build>
    <finalName>SpringBootES</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>