刚学完spring boot,然后学MybatisPlus,看着视频学酷酷报错
java.lang.String
Spring应用程序上下文中,有一个工厂bean的factoryBeanObjectType属性被设置为java.lang.String,而这被认为是无效的。
java.lang.IllegalStateException: Failed to load ApplicationContext for [MergedContextConfiguration@44841b43 testClass = com.atguigu.test.MybatisPlusTest, locations = [], classes = [com.atguigu.MainApplication], contextInitializerClasses = [], activeProfiles = [], propertySourceDescriptors = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"], contextCustomizers = [org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@10d307f1, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@5403f35f, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@383bfa16, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@21e360a, org.springframework.boot.test.context.SpringBootTestAnnotation@59a2f297], contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]
这个错误似乎是在加载Spring应用程序上下文时出现了问题,导致测试无法正常进行。具体来说,错误信息为:
Caused by: java.lang.IllegalArgumentException: Invalid value type for attribute 'factoryBeanObjectType': java.lang.String
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getTypeForFactoryBeanFromAttributes(FactoryBeanRegistrySupport.java:86)
这表明在Spring应用程序上下文中,有一个工厂bean的factoryBeanObjectType
属性被设置为java.lang.String
,而这被认为是无效的。
这可能是由于应用程序上下文配置中存在错误或不一致的bean定义引起的。以下是一些可能的解决方法:
-
**检查工厂bean配置:**检查您的应用程序上下文配置,尤其是工厂bean的定义。确保
factoryBeanObjectType
属性被正确设置,且与其期望的值类型匹配。 -
**排查配置问题:**查看最近是否有更改,尤其是与测试类、Spring配置或相关依赖项有关的更改。
-
**检查测试类注解:**确保您的测试类正确注解,特别是使用
@SpringBootTest
注解,并且任何其他注解或配置都是正确的。 -
**确认依赖项兼容性:**确保您的Spring Boot版本与其他相关依赖项的版本兼容。版本不匹配可能会导致不稳定性。
-
**查找工厂bean的问题:**如果您有自定义的工厂bean,确保它们的配置正确,特别是
factoryBeanObjectType
属性的设置。 -
**检查循环依赖:**在Spring bean中的循环依赖有时会导致问题。确保您的bean依赖关系没有引起冲突的循环依赖。
这些是chatgpt给我的答案,我自己怎么也解决不了,然后在csdn找到了大佬的一篇文章
发现
mybatis-spring 这个包版本应该比较低,造成不支持springboot3.2.0
于是,将依赖改成
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-3-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</exclusion>
</exclusions>
<version>1.2.20</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>3.0.3</version>
</dependency>
就可以运行了