最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Spring AI and Spring Cloud Compatibility Issue: JSON Parsing Error in OpenAI Chat Client - Stack Overflow

programmeradmin1浏览0评论

I have a working Spring AI project, but when I add dependencies for Spring Cloud (such as Eureka or Config Client), I get the following error when invoking the chat client.

Dependencies:

Spring Cloud Dependencies

<spring-ai.version>1.0.0-M6</spring-ai.version>
<spring-cloud.version>4.2.1</spring-cloud.version>

    <dependency>
    <groupId>.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    <version>${spring-cloud.version}</version>
</dependency>

<dependency>
    <groupId>.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-client</artifactId>
    <version>${spring-cloud.version}</version>
</dependency>

Spring AI Dependency

<dependency>
    <groupId>.springframework.ai</groupId>
    <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>

Version Management

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>.springframework.ai</groupId>
            <artifactId>spring-ai-bom</artifactId>
            <version>${spring-ai.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Error Log

2025-03-31T20:28:19.393+02:00 ERROR 53666 --- [nio-8084-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: .springframework.web.client.RestClientException: Error while extracting response for type [.springframework.ai.openai.api.OpenAiApi$ChatCompletion] and content type [application/json]] with root cause

    com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Object (start marker at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 1])
     at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 2]

Expected Behavior

The chat client should work correctly and return a response from OpenAI, even with Spring Cloud dependencies present.

Troubleshooting Done

The project works fine when Spring Cloud dependencies are removed.

The issue occurs when adding either spring-cloud-starter-netflix-eureka-client or spring-cloud-config-client.

The error suggests a JSON parsing issue, possibly due to an incomplete or malformed response.

Questions

Has anyone encountered compatibility issues between Spring AI 1.0.0-M6 and Spring Cloud 4.2.1?

Could Spring Cloud be interfering with the HTTP client used by Spring AI?

Are there any known fixes or workarounds?

Any help or suggestions would be greatly appreciated! Thanks in advance.

I have a working Spring AI project, but when I add dependencies for Spring Cloud (such as Eureka or Config Client), I get the following error when invoking the chat client.

Dependencies:

Spring Cloud Dependencies

<spring-ai.version>1.0.0-M6</spring-ai.version>
<spring-cloud.version>4.2.1</spring-cloud.version>

    <dependency>
    <groupId>.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    <version>${spring-cloud.version}</version>
</dependency>

<dependency>
    <groupId>.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-client</artifactId>
    <version>${spring-cloud.version}</version>
</dependency>

Spring AI Dependency

<dependency>
    <groupId>.springframework.ai</groupId>
    <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>

Version Management

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>.springframework.ai</groupId>
            <artifactId>spring-ai-bom</artifactId>
            <version>${spring-ai.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Error Log

2025-03-31T20:28:19.393+02:00 ERROR 53666 --- [nio-8084-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: .springframework.web.client.RestClientException: Error while extracting response for type [.springframework.ai.openai.api.OpenAiApi$ChatCompletion] and content type [application/json]] with root cause

    com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Object (start marker at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 1])
     at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 2]

Expected Behavior

The chat client should work correctly and return a response from OpenAI, even with Spring Cloud dependencies present.

Troubleshooting Done

The project works fine when Spring Cloud dependencies are removed.

The issue occurs when adding either spring-cloud-starter-netflix-eureka-client or spring-cloud-config-client.

The error suggests a JSON parsing issue, possibly due to an incomplete or malformed response.

Questions

Has anyone encountered compatibility issues between Spring AI 1.0.0-M6 and Spring Cloud 4.2.1?

Could Spring Cloud be interfering with the HTTP client used by Spring AI?

Are there any known fixes or workarounds?

Any help or suggestions would be greatly appreciated! Thanks in advance.

Share Improve this question edited Mar 31 at 18:57 Hilory 2,1417 gold badges14 silver badges30 bronze badges asked Mar 31 at 18:39 ZuzzuzZuzzuz 111 bronze badge 2
  • 1 Have you checked that the raw response (REDACTED) of the AI actually contains JSON? These AI models are known to sometimes not follow the requested JSON schema and answer with plain text or invalid JSON. Maybe it's a coincidence that this happened when you added a Spring Cloud library. – Dimitri Mestdagh Commented Mar 31 at 19:36
  • Hi, thanks for the suggestion. I can confirm that the issue only occurs when both Spring Cloud and Spring AI libraries are present. I've run several tests, and I can confidently say that the malfunction is caused by the simultaneous presence of the two libraries. – Zuzzuz Commented 14 hours ago
Add a comment  | 

1 Answer 1

Reset to default 0

If you want use a beta version of Spring AI (Spring AI 1.0.0-M6), You must use same period of versions of Spring Cloud (one beta version, not version 4.2.1 of Spring Cloud).

Best way: Use dependency management from Spring Boot and Spring Cloud (v2025.0.0-M1 https://github/spring-cloud/spring-cloud-release/releases) , all are latest snapshot version at this time of writing.

发布评论

评论列表(0)

  1. 暂无评论