Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required 启动错误信息

模块启动不起来报错:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

在启动类上加一下内容:

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})

可以解决上述异常------------------------

但是:

Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required异常就来了

配置文件必须是yml 不能是properties

所以 删掉 @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
启动Spring Boot项目报错"Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required"通常是由于配置不正确或缺少必要的配置导致的。根据引用中提到的问题,可能是以下几个原因导致的: 1. 缺少MyBatis的配置:确保在Spring Boot项目的配置文件中正确配置了MyBatis相关的属性,包括数据源、Mapper扫描路径等。 2. 缺少SqlSessionFactorySqlSessionTemplate的配置:在Spring Boot项目中,需要手动配置SqlSessionFactorySqlSessionTemplate。可以通过在配置类中使用@Bean注解来创建并配置它们。 3. 配置错误:检查配置文件中的属性名是否正确拼写,并确保属性值的类型正确。 以下是一个示例配置类,演示如何正确配置SqlSessionFactorySqlSessionTemplate: ```java @Configuration @MapperScan(basePackages = "com.example.mapper", sqlSessionTemplateRef = "sqlSessionTemplate") public class MyBatisConfig { @Autowired private DataSource dataSource; @Bean public SqlSessionFactory sqlSessionFactory() throws Exception { SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource); // 配置其他属性,如MapperLocations等 return sessionFactory.getObject(); } @Bean public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { return new SqlSessionTemplate(sqlSessionFactory); } } ``` 请注意,上述示例中的`com.example.mapper`是Mapper接口所在的包路径,你需要根据自己的项目结构进行相应的修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值