我花了整整一整天的时间寻找摆脱这种情况的方法。
序言
我的目标是将Spring Boot应用程序与其他两个已经工作的模块一起部署在EAR中。我克服了许多问题,因为Spring Boot应用程序的POM必须链接到父POM,因为其结构如下:
/ 父POM
-----> EAR POM
----->模块1 POM
----->模块2 POM
-----> Spring Boot App POM
问题
Spring Boot应用程序正确地将WAR打包,并成功放入Ear中。该战争出现在JBoss上,因为存在一些依赖问题。
我做了什么
我稍微玩过 jboss-deployment-structure.xml ,结果还是这样( restService 是Spring Boot应用程序) :
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
<deployment>
<exclusions>
<!-- WFCORE-209 workaround -->
<module name="javaee.api" />
<module name="org.hibernate.validator"/>
<module name="javax.persistence.api" />
<module name="org.hibernate" />
<!--<module name="javax.validation"/>-->
</exclusions>
<exclude-subsystems>
<subsystem name="jaxrs" />
<subsystem name="datasources" />
<subsystem name="ejb3" />
<subsystem name="infinispan" />
<subsystem name="jca" />
<subsystem name="logging" />
<subsystem name="jdr" />
<subsystem name="jpa" />
<subsystem name="jsf" />
<subsystem name="mail" />
<subsystem name="threads" />
<subsystem name="pojo" />
<subsystem name="sar" />
<subsystem name="transactions" />
<subsystem name="webservices" />
<subsystem name="weld" />
</exclude-subsystems>
<dependencies>
<!-- WFCORE-209 workaround -->
<module name="javax.activation.api" export="true"/>
<module name="javax.annotation.api" export="true"/>
<module name="javax.ejb.api" export="true"/>
<module name="javax.el.api" export="true"/>
<module name="javax.enterprise.api" export="true"/>
<module name="javax.enterprise.deploy.api" export="true"/>
<module name="javax.inject.api" export="true"/>
<module name="javax.interceptor.api" export="true"/>
<module name="javax.jms.api" export="true"/>
<module name="javax.jws.api" export="true"/>
<module name="javax.mail.api" export="true"/>
<module name="javax.management.j2ee.api" export="true"/>
<!-- <module name="javax.persistence.api" export="true"/> -->
<module name="javax.resource.api" export="true"/>
<module name="javax.rmi.api" export="true"/>
<module name="javax.security.auth.message.api" export="true"/>
<module name="javax.security.jacc.api" export="true"/>
<module name="javax.servlet.api" export="true"/>
<module name="javax.servlet.jsp.api" export="true"/>
<module name="javax.transaction.api" export="true"/>
<module name="javax.validation.api" export="true"/>
<module name="javax.ws.rs.api" export="true" services="export"/>
<module name="javax.xml.bind.api" export="true"/>
<module name="javax.xml.registry.api" export="true"/>
<module name="javax.xml.soap.api" export="true"/>
<module name="javax.xml.ws.api" export="true"/>
<!-- This one always goes last. -->
<module name="javax.api" export="true"/>
</dependencies>
</deployment>
<sub-deployment name="CRVbusinessService.war">
<dependencies>
<module name="javax.xml.rpc.api"/>
<module name="javax.wsdl4j.api"/>
</dependencies>
<exclusions>
<module name="org.apache.commons.logging"/>
<module name="org.apache.log4j"/>
<module name="org.jboss.logging"/>
<module name="org.jboss.logging.jul-to-slf4j-stub"/>
<module name="org.jboss.logmanager"/>
<module name="org.jboss.logmanager.log4j"/>
<module name="org.slf4j"/>
<module name="org.slf4j.impl"/>
</exclusions>
</sub-deployment>
<sub-deployment name="restService.war">
<local-last value="true" />
<dependencies>
<module name="deployment.jpa2.1"/>
</dependencies>
<exclusions>
<module name="org.jboss.logging"/>
<!--<module name="javax.validation"/>-->
<module name="javaee.api" />
</exclusions>
</sub-deployment>
<module name="deployment.jpa2.1" >
<module-alias name="jpa2.1"/>
<resources>
<resource-root path="hibernate-jpa-2.1-api-1.0.0.Final.jar" />
</resources>
</module>
</jboss-deployment-structure>
但是由于我实际上收到了此异常,所以无法解决问题:
应用程序运行失败: org.springframework.beans.factory.BeanCreationException:错误 创建在类路径中定义的名称为“ defaultValidator”的bean 资源 [org / springframework / boot / autoconfigure / validation / ValidationAutoConfiguration.class]: 调用init方法失败;嵌套异常为 java.lang.NoSuchMethodError: javax.validation.Configuration.getDefaultParameterNameProvider()Ljavax / validation / ParameterNameProvider;
为了在此处提供更多详细信息,它是Spring Boot应用程序pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>
<parent>
<groupId>it.test.businessService</groupId>
<artifactId>parent-parent</artifactId>
<version>0.0</version>
</parent>
<groupId>com.crvservice</groupId>
<artifactId>restService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<failOnMissingWebXml>false</failOnMissingWebXml>
<org.springframework-version>5.0.9.RELEASE</org.springframework-version>
<!--<hibernate.version>5.2.17.Final</hibernate.version>-->
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>development</id>
<properties>
<spring.profiles.active>dev</spring.profiles.active>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
<profile>
<id>production</id>
<properties>
<spring.profiles.active>ci</spring.profiles.active>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
</profiles>
</project>
在jboss-deployment-structure.xml中添加<module name="javax.validation"/>
似乎没有帮助,就像通过在Jboss上添加相对排除而解决的其他类似问题一样。我担心我的Spring Boot版本以及所连接的所有事物(如休眠)的级联太晚,无法在此JBoss版本上正常运行。
我想念什么吗?我环顾四周,但似乎很少有人真正需要这样做。
谢谢。
答案 0 :(得分:0)
问题似乎是由于Jboss 6仅支持Spring Boot版本1.5.x而不是2.x引起的。
请记住,Spring Boot 2.x在Jboss 3.0时仅支持Javax Servlet 3.1。