当前位置: 首页> 汽车> 车展 > 出现Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are requiredProperty报错

出现Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are requiredProperty报错

时间:2025/7/13 20:41:45来源:https://blog.csdn.net/m0_74436895/article/details/141459554 浏览次数: 0次

目录:

  • bug Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are requiredProperty
    • 报错
    • 解决方法

在这里插入图片描述

bug Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are requiredProperty

报错

在一个springboot demo启动的时候出现以下错误 ,
在这里插入图片描述

解决方法

1.启动类 里配置的 (@MapperScan(“com.example.demo.dao.mapper”)),这里开始配置错了

@EnableAsync
@EnableTransactionManagement//处理事务
@EnableScheduling//定时任务
@MapperScan(basePackages = {"com.jjy.easy_chat.mapper"})//这个地方路径写错该对即可
@SpringBootApplication(scanBasePackages = {"com.jjy.easy_chat"})
public class EasyChatApplication {public static void main(String[] args) {SpringApplication.run(EasyChatApplication.class, args);}}

2.application.yml 里配置的路径

mybatis:mapper-locations: classpath*:com/jjy/easy_chat/mapper/*.xml

3.检查mapper路径是否正确。若正确,查看在@EnableAutoConfiguration注解后,是否添加了exclude或者在@SpringBootApplication若有添加,尝试删除。(我的错误原因)

@EnableAsync
@EnableTransactionManagement//处理事务
@EnableScheduling//定时任务
@MapperScan(basePackages = {"com.jjy.easy_chat.mapper"})
@SpringBootApplication(scanBasePackages = {"com.jjy.easy_chat"},exclude = DataSourceAutoConfiguration.class)
public class EasyChatApplication {public static void main(String[] args) {SpringApplication.run(EasyChatApplication.class, args);}}

原因:

@SpringBootApplication,它组合了@Configuration, @EnableAutoConfiguration, 和 @ComponentScan注解的功能。下面是这个注解的一些关键点:
@SpringBootApplication: 这是Spring Boot的主启动类注解,它告诉Spring Boot应用从哪个包开始扫描组件。
exclude: 这个属性用来排除自动配置的类。在代码中,它排除了DataSourceAutoConfiguration,这意味着Spring Boot将不会自动配置数据源。

删除掉exclude里面的东西即可

如果我的内容对你有帮助,请点赞,评论,收藏。创作不易,大家的支持就是我坚持下去的动力
在这里插入图片描述

关键字:出现Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are requiredProperty报错

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: