springboot下Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

摘要:
已检查jar包是否已导入org。米巴蒂斯。春天启动mybatis spring boot starter1.3.2

已检查jar包是否引入

<dependency>
   <groupId>org.mybatis.spring.boot</groupId>
   <artifactId>mybatis-spring-boot-starter</artifactId>
   <version>1.3.2</version>
</dependency>

还有一种是从某个版本后mybatis没有自动注入sqlSessionFactory

手动创建注入设置类

packagecom.example.demo.config;

importcom.alibaba.druid.pool.DruidDataSource;
importorg.apache.ibatis.session.SqlSessionFactory;
importorg.mybatis.spring.SqlSessionFactoryBean;
importorg.springframework.beans.factory.annotation.Autowired;
importorg.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
importorg.springframework.context.annotation.Bean;
importorg.springframework.context.annotation.Configuration;

importjavax.sql.DataSource;

/*** @authorcanger
 * @Deseription
 * @create 2019/2/25 16:30
 **/@Configuration
public classMybatisConfig {

    @Autowired
    privateDataSourceProperties dataSourceProperties;


    @Bean(name = "dataSource")
    publicDataSource dataSource() {

        DruidDataSource dataSource = newDruidDataSource();
        dataSource.setUrl(dataSourceProperties.getUrl());
        System.out.println(dataSourceProperties.getUrl());
        dataSource.setDriverClassName(dataSourceProperties.getDriverClassName());
        dataSource.setUsername(dataSourceProperties.getUsername());
        dataSource.setPassword(dataSourceProperties.getPassword());

        returndataSource;

    }

    public SqlSessionFactory sqlSessionFactory() throwsException {
        SqlSessionFactoryBean sqlSessionFactoryBean = newSqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource());
        returnsqlSessionFactoryBean.getObject();
    }

}

免责声明:文章转载自《springboot下Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇理解 LDA 主题模型Windows之权限的继承性 累加性 优先性 交叉性及四项基本原则下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

PowerDesigner 15 使用技巧

1.检索PowerDesigner的调色板工具栏工具&gt;自定义大小工具栏&gt;调色板检查2。在表格工具中批量修改文本格式&gt;显示首选项&gt;选择符号中的所有项目&gt;...

Android 上的 10 款 Web 开发工具推荐

作为一个狂热的Android用户,我一直在寻找适合Web开发人员使用的一些应用程序。以下推荐10款非常实用的Android端的Web开发工具。EditorJoooid1.1Editor这款工具非常适合用来发布包含HTML、文本、图片和相册的文章,还包含了GPL定位信息。...

说说接口封装

今天,我为同事封装了一个接口。当谈到接口封装时,有很多关于它的讨论。在很多情况下,说一个服务好,一个服务坏,实际上是在吐槽服务团队之外暴露的界面质量。无论哪种语言,抽象的封装接口都由一个函数名、几个参数和几个返回值组成。总之,参数不应该被封装……我们在内部尝试接口_Catch不会抛出异常,所有信息都将以错误代码的形式返回。就php而言,建议进行异常处理。...

backgroundsize

当背景大小值为和时,可以设置两个值,也可以设置一个值。当只取一个值时,第二个值相当于auto,但此处的auto不会将背景图像的高度保持在其原始高度,而是与第一个值相同。此外,如果只取一个值,宽度和高度将相同,这相当于背景大小:80%自动。...

nginx配置跨域(CORS)、防盗链(valid_referers)、缓存(expires)、压缩(gzip)

它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从而克服AJAX只能同源使用的限制。服务器根据这个值,在许可范围内,则在头信息包含Access-Control-Allow-Origin。...

winform窗体(六)——DataGridView控件及通过此控件中实现增删改查

“,”Delete Data“,btn)==DialogResult.Yes){}V.多条件查询。如果用户没有输入任何内容或文本框为空,则查询所有内容。//设置两个常量条件stringtj1=”1=1“;stringtj2=”1=1”;//根据用户的输入更改条件。//如果用户输入名称If(name!=”“){tj1=“Namelike@name“;}//如果...