SpringBoot 整合 Mybatis 时可能会出现 :Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required 的错误,在网上找了一些原基因和解决办法,总结一下:
原因:
使用STS创建的SpringBoot项目,其中配置文件默认的是application.properties,一般在这个文件里面配置数据源。但是这个文件想要起作用,则必须在配置主类中加入@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})自动注入,否则该配置文件中的配置无效。会报出Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.错误(这个是我尝试过的,确实是这样。)
解决办法:
在 pom.xml 文件中添加 druid 的引用即可(我也不知道为啥~);
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.9</version>
</dependency>