【错误解决】No qualifying bean of type ‘com.alibaba.druid.pool.DruidDataSource‘ available

易奇希
2023-12-01

ssm框架整合一直报错:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.alibaba.druid.pool.DruidDataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
最后排查发现原因,配置MybatisConfig时候,依赖注入那里一直写的是DruidDataSource dataSource:

@Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean(DruidDataSource dataSource){
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource);
        sqlSessionFactoryBean.setTypeAliasesPackage("com.zcongfly.pojo");
        return sqlSessionFactoryBean;
    }

改成DruidDataSource dataSource就能跑了:

@Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource){
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource);
        sqlSessionFactoryBean.setTypeAliasesPackage("com.zcongfly.pojo");
        return sqlSessionFactoryBean;
    }

我他喵,好想扇死自己。。。

 类似资料: