Разверните приложение SpringBoot в JBOSS EAP 6.4 - PullRequest
0 голосов
/ 21 марта 2019

Я хотел бы создать простой привет-мир, такой как REST Application, в Springboot и развернуть его в JBOSS EAP 6.4.

У меня есть только одна конечная точка: GET запрос к /api/logparser и возврат json

Мне удалось создать файл war и запустить его без проблем. Я думаю, что проблема в моих web.xml и настройках контекста, но я не могу понять, что вызвало ошибку.

Мой проект выглядит следующим образом:

build.gradle

plugins {
    id 'org.springframework.boot' version '2.1.3.RELEASE'
    id 'java'
    id 'war'
}

apply plugin: 'io.spring.dependency-management'

version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
} 

Application.java

package com.custom.logparser;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

Мой контроллер LogFileController.java

package com.custom.logparser;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LogFileController {

    @RequestMapping("/api/logparser/getlog")
    public LogFile greeting() {
        return new LogFile("logFileContent");
    }
}

LogFile.java

package com.custom.logparser;

public class LogFile {

    private final String content;

    public LogFile(String content) {
        this.content = content;
    }

    public String getContent() {
        return content;
    }
}

Я создал ServletInitializer.java

package com.custom.logparser;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/dispatcher-config.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

</web-app>

диспетчер-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">

    <context:annotation-config/>

    <context:component-scan base-package="com.custom.logparser"/>

</beans>

Я забыл прикрепить сообщение об ошибке: http://s000.tinyupload.com/?file_id=05005994728105632903

2019-03-22 09:50:32,637 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting deployment of "logparser-web-service-0.0.1-SNAPSHOT.war" (runtime-name: "logparser-web-service-0.0.1-SNAPSHOT.war")
2019-03-22 09:50:32,795 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015852: Could not index class META-INF/versions/9/module-info.class at /content/logparser-web-service-0.0.1-SNAPSHOT.war/WEB-INF/lib/log4j-api-2.11.2.jar: java.lang.IllegalStateException: Unknown tag! pos=4 poolCount = 32

2019-03-22 09:50:33,106 INFO  [org.jboss.weld.deployer] (MSC service thread 1-3) JBAS016002: Processing weld deployment logparser-web-service-0.0.1-SNAPSHOT.war
2019-03-22 09:50:33,124 INFO  [org.jboss.weld.deployer] (MSC service thread 1-4) JBAS016005: Starting Services for CDI deployment: logparser-web-service-0.0.1-SNAPSHOT.war
2019-03-22 09:50:33,127 INFO  [org.jboss.weld.deployer] (MSC service thread 1-8) JBAS016008: Starting weld service for deployment logparser-web-service-0.0.1-SNAPSHOT.war
2019-03-22 09:50:33,165 INFO  [org.jboss.web] (ServerService Thread Pool -- 1046) JBAS018210: Register web context: /logparser-web-service-0.0.1-SNAPSHOT
2019-03-22 09:50:33,177 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/logparser-web-service-0.0.1-SNAPSHOT]] (ServerService Thread Pool -- 1046) 2 Spring WebApplicationInitializers detected on classpath
2019-03-22 09:50:33,347 INFO  [stdout] (ServerService Thread Pool -- 1046)
2019-03-22 09:50:33,347 INFO  [stdout] (ServerService Thread Pool -- 1046)   .   ____          _            __ _ _
2019-03-22 09:50:33,347 INFO  [stdout] (ServerService Thread Pool -- 1046)  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
2019-03-22 09:50:33,347 INFO  [stdout] (ServerService Thread Pool -- 1046) ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2019-03-22 09:50:33,347 INFO  [stdout] (ServerService Thread Pool -- 1046)  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
2019-03-22 09:50:33,347 INFO  [stdout] (ServerService Thread Pool -- 1046)   '  |____| .__|_| |_|_| |_\__, | / / / /
2019-03-22 09:50:33,348 INFO  [stdout] (ServerService Thread Pool -- 1046)  =========|_|==============|___/=/_/_/_/
2019-03-22 09:50:33,348 INFO  [stdout] (ServerService Thread Pool -- 1046)  :: Spring Boot ::        (v2.1.3.RELEASE)
2019-03-22 09:50:33,348 INFO  [stdout] (ServerService Thread Pool -- 1046)
2019-03-22 09:50:33,396 INFO  [com.custom.logparser.ServletInitializer] (ServerService Thread Pool -- 1046) Starting ServletInitializer on webserverpe480 with PID 500 (started by eea in /usr/share/jbossas)
2019-03-22 09:50:33,397 INFO  [com.custom.logparser.ServletInitializer] (ServerService Thread Pool -- 1046) No active profile set, falling back to default profiles: default
2019-03-22 09:50:33,844 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/logparser-web-service-0.0.1-SNAPSHOT]] (ServerService Thread Pool -- 1046) Initializing Spring embedded WebApplicationContext
2019-03-22 09:50:33,845 INFO  [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 1046) Root WebApplicationContext: initialization completed in 432 ms
2019-03-22 09:50:34,036 WARN  [org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext] (ServerService Thread Pool -- 1046) Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.validation.Configuration.getDefaultParameterNameProvider()Ljavax/validation/ParameterNameProvider;
2019-03-22 09:50:34,041 INFO  [org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener] (ServerService Thread Pool -- 1046)

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-03-22 09:50:34,043 ERROR [org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter] (ServerService Thread Pool -- 1046)

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call the method javax.validation.Configuration.getDefaultParameterNameProvider()Ljavax/validation/ParameterNameProvider; but it does not exist. Its class, javax.validation.Configuration, is available from the following locations:

    jar:file:/opt/jboss-eap/modules/system/layers/base/javax/validation/api/main/validation-api.jar!/javax/validation/Configuration.class
    vfs:/content/logparser-web-service-0.0.1-SNAPSHOT.war/WEB-INF/lib/validation-api-2.0.1.Final.jar/javax/validation/Configuration.class

It was loaded from the following location:

    jar:file:/opt/jboss-eap/modules/system/layers/base/javax/validation/api/main/validation-api.jar!/


Action:

Correct the classpath of your application so that it contains a single, compatible version of javax.validation.Configuration
2019-03-22 09:50:34,043 ERROR [org.jboss.web] (ServerService Thread Pool -- 1046) JBAS018202: Error calling onStartup for servlet container initializer: org.springframework.web.SpringServletContainerInitializer: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.validation.Configuration.getDefaultParameterNameProvider()Ljavax/validation/ParameterNameProvider;
2019-03-22 09:50:34,045 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/logparser-web-service-0.0.1-SNAPSHOT]] (ServerService Thread Pool -- 1046) JBWEB000287: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!
2019-03-22 09:50:34,046 ERROR [org.apache.catalina.core] (ServerService Thread Pool -- 1046) JBWEB001103: Error detected during context /logparser-web-service-0.0.1-SNAPSHOT start, will stop it
2019-03-22 09:50:34,049 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/logparser-web-service-0.0.1-SNAPSHOT]] (ServerService Thread Pool -- 1046) Closing Spring root WebApplicationContext
2019-03-22 09:50:34,050 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 1046) MSC000001: Failed to start service jboss.web.deployment.default-host."/logparser-web-service-0.0.1-SNAPSHOT": org.jboss.msc.service.StartException in service jboss.web.deployment.default-host."/logparser-web-service-0.0.1-SNAPSHOT": org.jboss.msc.service.StartException in anonymous service: JBAS018040: Failed to start context

Что я пропустил?

...