spring-ai-starter-mcp-server-webmvc的包冲突
·
搭建spring-ai的mcp服务,引用官网的包
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.my.mcp.tools</groupId>
<artifactId>mcp_tools</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>21</java.version>
<spring-boot.version>3.2.5</spring-boot.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</project>
启动类:
package org.my.mcp.tools;
import org.my.mcp.tools.service.WeatherService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class ServerStart {
private static final Logger logger = LoggerFactory.getLogger(ServerStart.class);
public static void main(String[] args) {
SpringApplication.run(ServerStart.class, args);
}
@Bean
public ToolCallbackProvider weatherTools(WeatherService weatherService) {
return MethodToolCallbackProvider.builder().toolObjects(weatherService).build();
}
}
启动后报错:jackson冲突
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.NoClassDefFoundError: com/fasterxml/jackson/annotation/JsonSerializeAs [in thread "background-preinit"]
经过Dependency Analyzer分析后,需要约束一下版本,解决包冲突:
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.my.mcp.tools</groupId>
<artifactId>mcp_tools</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>21</java.version>
<spring-boot.version>3.2.5</spring-boot.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<artifactId>jackson-databind</artifactId>
<groupId>tools.jackson.core</groupId>
<version>3.1.4</version>
</dependency>
<dependency>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
<version>2.0.17</version>
</dependency>
<dependency>
<artifactId>jackson-annotations</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<version>2.21</version>
</dependency>
<dependency>
<artifactId>jackson-core</artifactId>
<groupId>tools.jackson.core</groupId>
<version>3.1.4</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</project>
启动成功:
Connected to the target VM, address: '127.0.0.1:50454', transport: 'socket'
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v4.1.0)
[serverAnnotatedMethodBeanPostProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies/advisors. If this bean does not have to be post-processed, declare it with ROLE_INFRASTRUCTURE.
2026-06-24T09:30:10.116+08:00 WARN 4520 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'serverAnnotatedBeanRegistry' of type [org.springframework.ai.mcp.server.common.autoconfigure.annotations.McpServerAnnotationScannerAutoConfiguration$ServerMcpAnnotatedBeans] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected/applied to a currently created BeanPostProcessor [serverAnnotatedMethodBeanPostProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies/advisors. If this bean does not have to be post-processed, declare it with ROLE_INFRASTRUCTURE.
2026-06-24T09:30:10.126+08:00 WARN 4520 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.ai.mcp.server.annotation-scanner-org.springframework.ai.mcp.server.common.autoconfigure.annotations.McpServerAnnotationScannerProperties' of type [org.springframework.ai.mcp.server.common.autoconfigure.annotations.McpServerAnnotationScannerProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected/applied to a currently created BeanPostProcessor [serverAnnotatedMethodBeanPostProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies/advisors. If this bean does not have to be post-processed, declare it with ROLE_INFRASTRUCTURE.
2026-06-24T09:30:10.424+08:00 INFO 4520 --- [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)
2026-06-24T09:30:10.440+08:00 INFO 4520 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2026-06-24T09:30:10.440+08:00 INFO 4520 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/11.0.22]
2026-06-24T09:30:10.499+08:00 INFO 4520 --- [ main] b.w.c.s.WebApplicationContextInitializer : Root WebApplicationContext: initialization completed in 1058 ms
2026-06-24T09:30:11.124+08:00 INFO 4520 --- [ main] o.s.a.m.s.c.a.McpServerAutoConfiguration : Enable tools capabilities, notification: true
2026-06-24T09:30:11.212+08:00 WARN 4520 --- [ main] o.s.a.m.a.p.tool.SyncMcpToolProvider : No tool methods found in the provided tool objects: []
2026-06-24T09:30:11.213+08:00 INFO 4520 --- [ main] o.s.a.m.s.c.a.McpServerAutoConfiguration : Registered tools: 1
2026-06-24T09:30:11.213+08:00 INFO 4520 --- [ main] o.s.a.m.s.c.a.McpServerAutoConfiguration : Enable resources capabilities, notification: true
2026-06-24T09:30:11.217+08:00 INFO 4520 --- [ main] o.s.a.m.s.c.a.McpServerAutoConfiguration : Enable resources templates capabilities, notification: true
2026-06-24T09:30:11.219+08:00 INFO 4520 --- [ main] o.s.a.m.s.c.a.McpServerAutoConfiguration : Enable prompts capabilities, notification: true
2026-06-24T09:30:11.222+08:00 INFO 4520 --- [ main] o.s.a.m.s.c.a.McpServerAutoConfiguration : Enable completions capabilities
2026-06-24T09:30:11.405+08:00 INFO 4520 --- [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/'
2026-06-24T09:30:11.410+08:00 INFO 4520 --- [ main] org.my.mcp.tools.ServerStart : Started ServerStart in 2.578 seconds (process running for 3.187)
更多推荐
所有评论(0)