Error creating bean with name 'dataCollectApplication': Unsatisfied dependency expressed through field 'addrCodeService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'addrCodeServiceImpl': Unsatisfied dependency expressed through field 'addrCodeDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addrCodeDao' defined in file [D:\作业\犇云\数据采集项目\DataCollect\target\classes\com\dzero\datacollect\dao\AddrCodeDao.class]: Cannot resolve reference to bean 'sqlSessionTemplate' while setting bean property 'sqlSessionTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionTemplate' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\作业\犇云\数据采集项目\DataCollect\target\classes\mapper\addrCodeMapper.xml]'; nested exception is java.lang.StringIndexOutOfBoundsException: begin 1, end 0, length 1
时间: 2024-04-18 09:30:17 浏览: 14
根据错误信息来看,出现了多个依赖注入相关的异常。首先,出现了 `UnsatisfiedDependencyException` 异常,表示存在依赖注入失败的情况。具体的错误信息是 `Error creating bean with name 'addrCodeServiceImpl': Unsatisfied dependency expressed through field 'addrCodeDao'`,说明在 `addrCodeServiceImpl` 类中的 `addrCodeDao` 字段的注入失败。
进一步看到,`addrCodeDao` 的注入失败是由于 `Error creating bean with name 'addrCodeDao'` 引起的。错误信息中指出了 `Cannot resolve reference to bean 'sqlSessionTemplate' while setting bean property 'sqlSessionTemplate'`,表示在设置 `addrCodeDao` 的依赖属性 `sqlSessionTemplate` 时无法解析对 `sqlSessionTemplate` Bean 的引用。
继续查看错误信息,发现在创建 `sqlSessionTemplate` Bean 时,又出现了 `UnsatisfiedDependencyException` 异常。具体的错误信息是 `Error creating bean with name 'sqlSessionTemplate' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionTemplate' parameter 0`。
最后,可以看到在创建 `sqlSessionFactory` Bean 时,又抛出了异常。具体的错误信息是 `Failed to parse mapping resource: 'file [D:\作业\犇云\数据采集项目\DataCollect\target\classes\mapper\addrCodeMapper.xml]'`,表示解析 XML 映射文件 `addrCodeMapper.xml` 失败。
总结来说,根据错误信息看起来是 MyBatis 配置或映射文件的问题导致的异常。你需要检查以下几点:
1. 确保 `addrCodeMapper.xml` 文件存在于指定的路径 `D:\作业\犇云\数据采集项目\DataCollect\target\classes\mapper\` 下,并且文件内容正确。
2. 检查 MyBatis 配置是否正确,特别是与 `sqlSessionFactory` 和 `sqlSessionTemplate` 相关的配置。
3. 确保 MyBatis 的依赖和版本与 Spring Boot 版本兼容,并且在构建文件中正确引入了相关的依赖。
如果你能提供更多关于 MyBatis 配置和映射文件的信息,我可以帮助你更好地分析和解决这个问题。