简体   繁体   English

Spring boot 2.4.5 REST WS WAR into glassfish 5 端点运行应用程序错误

[英]Spring boot 2.4.5 REST WS WAR into glassfish 5 error in endpoint running app

Hello everyone can someone help me understand why this problem occurs...大家好,有人可以帮我理解为什么会出现这个问题...

Basically I have created a REST WS with Maven and have built a WAR file to deploy into Glassfish 5 and have an error when I access one of the endpoints.基本上,我使用 Maven 创建了一个 REST WS,并构建了一个 WAR 文件以部署到 Glassfish 5 中,并且在访问其中一个端点时出现错误。

Otherwise if I deploy the same WAR into Tomcat 9, the same call to the endpoint run´s well.否则,如果我将相同的 WAR 部署到 Tomcat 9,对端点的相同调用运行良好。

The deployment process occurs with no fuss and the REST endpoints work in both.部署过程没有大惊小怪,REST 端点在两者中都可以工作。

JAVA_HOME is the same for both AS, configured to run in Java 1.8. JAVA_HOME 对于两个 AS 是相同的,配置为在 Java 1.8 中运行。

But in a particular call to an endpoint this error is thrown:但是在对端点的特定调用中会引发此错误:

2021-11-05 15:59:03 [http-listener-1(3)] ERROR ErrorPageFilter[forwardToErrorPage:184] - Forwarding to error page from request [/candidatos/1] due to exception [com.fasterxml.jackson.databind.ser.std.ReferenceTypeSerializer.withResolved(Lcom/fasterxml/jackson/databind/BeanProperty;Lcom/fasterxml/jackson/databind/jsontype/TypeSerializer;Lcom/fasterxml/jackson/databind/JsonSerializer;Lcom/fasterxml/jackson/databind/util/NameTransformer;Lcom/fasterxml/jackson/annotation/JsonInclude$Include;)Lcom/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer;]
java.lang.AbstractMethodError: com.fasterxml.jackson.databind.ser.std.ReferenceTypeSerializer.withResolved(Lcom/fasterxml/jackson/databind/BeanProperty;Lcom/fasterxml/jackson/databind/jsontype/TypeSerializer;Lcom/fasterxml/jackson/databind/JsonSerializer;Lcom/fasterxml/jackson/databind/util/NameTransformer;Lcom/fasterxml/jackson/annotation/JsonInclude$Include;)Lcom/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer;
      at com.fasterxml.jackson.databind.ser.std.ReferenceTypeSerializer.createContextual(ReferenceTypeSerializer.java:167)
      at com.fasterxml.jackson.databind.SerializerProvider.handleSecondaryContextualization(SerializerProvider.java:966)
      at com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:514)
      at com.fasterxml.jackson.databind.SerializerProvider.findTypedValueSerializer(SerializerProvider.java:698)
      at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:270)
      at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1429)
      at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:951)
      at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:454)
      at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:104)
      at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:290)
      at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:181)
      at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:78)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:124)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1060)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:962)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
      at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:686)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:791)
      at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1580)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:338)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:250)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:126)
      at org.springframework.boot.web.servlet.support.ErrorPageFilter.access$000(ErrorPageFilter.java:64)
      at org.springframework.boot.web.servlet.support.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:101)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
      at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:119)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:250)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:250)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:250)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:652)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:591)
      at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
      at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
      at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)
      at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
      at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242)
      at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
      at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
      at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)
      at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
      at java.lang.Thread.run(Thread.java:748)

pom.xml pom.xml

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.5</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<packaging>war</packaging>
<groupId>recrutamento</groupId>
<artifactId>recrutamento</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>recrutamento</name>
<description>Projeto de webservices para recrutamento</description>
<properties>
    <java.version>1.8</java.version>
    <tomcat.version>9.0.54</tomcat.version>
</properties>
<dependencies>
    <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-web</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-data-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <!-- Caso se pretenda fazer deploy deste war para outro Servidor Aplicacional -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>23.0</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>animal-sniffer-annotations</artifactId>
        <version>1.14</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>5.0.0</version>
    </dependency> 
</dependencies>
<build>
    <defaultGoal>spring-boot:run</defaultGoal>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <configuration>
            <failOnMissingWebXml>false</failOnMissingWebXml>
          </configuration>
        </plugin>
    </plugins>
</build>

Controller控制器

@RequestMapping("/candidatos/{chave}")
public Optional<Candidato> getCandidatoID(@PathVariable("chave") Integer chave) {
    return servicoRecrutamento.getCandidatoID(chave);
}

Service服务

public Optional<Candidato> getCandidatoID(Integer chave) {
    Optional<Candidato> candidato = candidatoRepository.findById(chave);
    if(!candidato.isPresent()){
        throw new EntityNotFoundException("Record with "+chave+" not found");
    }
        return candidato;
}

candidatoRepository候选存储库

package application.entities.repositories;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import application.entities.Candidato;
@ComponentScan
@Repository
public interface CandidatoRepository extends JpaRepository<Candidato, 
 Integer>,JpaSpecificationExecutor<Candidato>{

}

You say that there is a difference in observed behaviour between Tomcat and Glassfish .您说TomcatGlassfish之间观察到的行为存在差异。

If we look at the log output, we will see that there is java.lang.AbstractMethodError thrown.如果我们查看日志输出,我们会看到抛出了java.lang.AbstractMethodError

If we looks into Oracle docs we can see that its thrown when ...如果我们查看Oracle 文档,我们可以看到它在...

Thrown when an application tries to call an abstract method.当应用程序尝试调用抽象方法时抛出。 Normally, this error is caught by the compiler;通常,这个错误是由编译器捕获的; this error can only occur at run time if the definition of some class has incompatibly changed since the currently executing method was last compiled.如果自上次编译当前执行的方法以来某个类的定义发生了不兼容的更改,则此错误只会在运行时发生。

In practice, this occurs because some dependency versions in your app have an incompatability.实际上,这是因为您的应用程序中的某些依赖项版本不兼容。 You can see an example of a scenario when this can play out here .您可以在此处查看出现这种情况的场景示例。

If we look closer at the error message we can see the following如果我们仔细查看错误消息,我们可以看到以下内容

java.lang.AbstractMethodError: com.fasterxml.jackson.databind.ser.std.ReferenceTypeSerializer.withResolved(Lcom/fasterxml/jackson/databind/BeanProperty;Lcom/fasterxml/jackson/databind/jsontype/TypeSerializer;Lcom/fasterxml/jackson/databind/JsonSerializer;Lcom/fasterxml/jackson/databind/util/NameTransformer;Lcom/fasterxml/jackson/annotation/JsonInclude$Include;)Lcom/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer; java.lang.AbstractMethodError: com.fasterxml.jackson.databind.ser.std.ReferenceTypeSerializer.withResolved(Lcom/fasterxml/jackson/databind/BeanProperty;Lcom/fasterxml/jackson/databind/jsontype/TypeSerializer;Lcom/fasterxml/jackson/ databind/JsonSerializer;Lcom/fasterxml/jackson/databind/util/NameTransformer;Lcom/fasterxml/jackson/annotation/JsonInclude$Include;)Lcom/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer;

So, OK ... why can it happen ?所以,好吧……为什么会发生? Spring Boot apps use Jackson for serialisation and deserialisation and typically run on an embedded Tomcat , which has some stuff of the right versions to enable it to work. Spring Boot 应用程序使用Jackson进行序列化和反序列化,并且通常在嵌入式Tomcat上运行,该Tomcat具有一些正确版本的内容以使其能够工作。 It seems that something is very different on Glassfish, it must supply some jars , which cause this incompatiability. Glassfish 上似乎有一些非常不同的东西,它必须提供一些jars ,这导致了这种不兼容。

The easiest solution seems to be to use the next version of Glassfish , which is 6.0 ... hopefully, it contains some more modern jars, which are compatiable with Spring Boot's jackson.最简单的解决方案似乎是使用Glassfish的下一个版本,即 6.0 ...希望它包含一些更现代的 jars,它们与 Spring Boot 的 jackson 兼容。

Otherwise, I think, you'll need to change the version of Jackson Glassfish v 5.0 is using ... to make it compatiable with Spring Boot.否则,我认为,您需要更改Jackson Glassfish v 5.0 正在使用的版本......以使其与 Spring Boot 兼容。

Or change the version of Jackson SpringBoot is using to make it compatiable with Glasshfish version.或者更改Jackson SpringBoot 使用的版本,使其与 Glasshfish 版本兼容。

This gives a solution strategy.这给出了解决策略。 If you still have further questions, please post in the comments to this answer.如果您还有其他问题,请在此答案的评论中留言。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM