另一个服务 JAR 正在创建 Spring 的自动配置(创建名为"mongoTemplate"的 bean 时出错)



我有一个Java春季启动应用程序(称之为实用程序服务(和许多其他Java春季启动程序(称它们为客户端(。

两者(实用程序服务和客户端(都使用Spring的自动配置。当我试图将实用程序服务的JAR放入客户端时,在构建客户端之后,它在bootrun处抛出错误。错误为:

Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: 
Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.data.mongodb.MongoDbFactory]: : 
Error creating bean with name 'mongoDbFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: 
Unsatisfied dependency expressed through constructor argument with index 0 of type [com.mongodb.MongoClient]: : 
Error creating bean with name 'mongo' defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]: 
Bean instantiation via factory method failed; 
nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [com.mongodb.MongoClient]: 
Factory method 'mongo' threw exception; 
nested exception is java.lang.NoSuchMethodError: 
org.bson.io.BasicOutputBuffer.<init>(I)V; 

我可以通过在客户端的Application.java中应用@EnableAutoConfiguration(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})来解决这个问题。

但我有很多这样的客户端,我不想修改客户端的代码(除了build.gradle(。

公用事业服务是否有任何方法可以修改和实现上述内容?

当在任何客户端中包含依赖项时,可以尝试排除该类。一旦排除了mongoTemplate配置类,它就不应该在构建客户端服务代码时出现在类路径中。

希望这能有所帮助。

最新更新