我无法在 JBOSS EAP 7 服务器上部署我的 Spring BOOT REST 应用程序。
但是,它在 Apache Tomcat 8 服务器上部署后运行良好。
应用程序主类:
@SpringBootApplication(scanBasePackages= {"org.nic"})
@PropertySource(value="classpath:database.properties")
public class PopulationApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(PopulationApplication.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(PopulationApplication.class, args);
}
}
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<start-class>org.nic.PopulationApplication</start-class>
</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>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
它在服务器日志中抛出以下错误
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter]: Factory method 'httpPutFormContentFilter' threw exception; nested exception is java.lang.VerifyError: Failed to link com/fasterxml/jackson/databind/type/ReferenceType (Module "deployment.nhpmapi-0.0.1-SNAPSHOT.war:main" from Service Module Loader): Cannot inherit from final class
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:579)
... 35 more
我的服务器环境只有 JBOSS EAP 7。
我进行了研究来解决这个问题,但没有成功。
我最后选择删除 Spring BOOT 配置以便在 JBOSS EAP 7 上运行
最佳答案
我遇到了完全相同的问题并且苦苦挣扎了两天。终于找到解决办法了!
java.lang.VerifyError
通常是类不一致导致的。
如报错信息所示,是由com.fasterxml.jackson.core.jackson-databind
引起的
由于Jboss有其内部的Jackson模块,而且它的版本与您指定的应用程序不同。
解决问题,添加jboss-deployment-structure.xml
,放在src/main/webapp/WEB-INF
下:
<?xml version='1.0' encoding='UTF-8'?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
<deployment>
<exclusions>
<module name="com.fasterxml.jackson.core.jackson-annotations" />
<module name="com.fasterxml.jackson.core.jackson-core" />
<module name="com.fasterxml.jackson.core.jackson-databind" />
<module name="com.fasterxml.jackson.datatype.jackson-datatype-jdk8"/>
<module name="com.fasterxml.jackson.datatype.jackson-datatype-jsr310"/>
<module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider" />
<module name="org.jboss.resteasy.resteasy-jackson2-provider" />
<module name="org.slf4j" />
</exclusions>
</deployment>
</jboss-deployment-structure>
它将避免隐式依赖并解决问题。
找到答案here和 here和 here感谢他们!
更多信息:
Causes of getting a java.lang.VerifyError
What is jboss-deployment-structure.xml
Module Dependencies
关于java - jboss eap 7 上的 spring boot 应用程序部署失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50778988/